I am looking for a method to format time via timestamp() in 24 hr or military format. VFE default appears to be HH:MM AM/PM. I am not finding anything that suggests there are options...
Thanks in advance.
I wrote this a while ago to get "military time"
/* Military Time */ DOCUMENT.TIMESIZE = size(TIMESTAMP()) DOCUMENT.AM_PM = sub(str(TIMESTAMP()),DOCUMENT.TIMESIZE - 1) DOCUMENT.TIME = sub(str(TIMESTAMP()),1,DOCUMENT.TIMESIZE - 3) COND CASE DOCUMENT.AM_PM = "AM" AND SUB(DOCUMENT.TIME,1,2) = 12 DOCUMENT.MILTIME = replacestr(DOCUMENT.TIME,"12:","00") CASE DOCUMENT.AM_PM = "AM" DOCUMENT.MILTIME = replacestr(DOCUMENT.TIME,":","") CASE DOCUMENT.AM_PM = "PM" AND SUB(DOCUMENT.TIME,1,2) = 12 DOCUMENT.MILTIME = replacestr(DOCUMENT.TIME,":","") CASE DOCUMENT.AM_PM = "PM" DOCUMENT.MILTIME = replacestr(DOCUMENT.TIME,":","") DOCUMENT.MILTIME = val(DOCUMENT.MILTIME) + val("1200") ENDCOND if (size(str(DOCUMENT.MILTIME))= 3) then DOCUMENT.FORMATTED_MILTIME = "0" + str(DOCUMENT.MILTIME) else DOCUMENT.FORMATTED_MILTIME = str(DOCUMENT.MILTIME) endif
David Shower
OU Tulsa School of Community Medicine
Excellent! I'll try this out.
Thank you.
As a follow up to this question, I've run into another hurdle.
The OBS term field I am wanting to store the results of the military time conversion is a number field.
I have been digging around for a few hours now looking for a method to convert the string to a number so it will accept it. My arrangement of code works with OBS terms that are text fields, but not with this OBS term (N), so I assume that's my issue.
Thanks in advance - again.
Try the val(string) function. Turns a string of characters into a value. The problem doing that is if your time is 0400 for example, it is going to drop the leading zero. I you ever need to use the value stored in the obs term you may have to do a length test and prepend a zero if the length is 3.
David Shower
OU Tulsa School of Community Medicine
OK. Thank you again.
This fairly simple project is kicking my butt.
If I point the button at a document variable it works perfect.
If I point the button at a random text OBS it seems to work fine.
If I point it at any of the OBS terms that I need to populate it doesn't work (examples below).
I added a datadisplay to check the variable as it goes through the process and sometimes that doesn't even get populated when using the troublesome OBS term. In that case the button doesn't do anything at all. In my test form it works using a different OBS term or a document variable.
Here's the Code as I am using it (I've added a couple minor things).
{
DOCUMENT.TIMESIZE = size(TIMESTAMP())
DOCUMENT.AM_PM = sub(str(TIMESTAMP()),DOCUMENT.TIMESIZE - 1)
DOCUMENT.TIME = sub(str(TIMESTAMP()),1,DOCUMENT.TIMESIZE - 3)
DOCUMENT.TIMEHOLD = ""
COND
CASE DOCUMENT.AM_PM = "AM" AND SUB(DOCUMENT.TIME,1,2) = 12
DOCUMENT.MILTIME = replacestr(DOCUMENT.TIME,"12:","00")
CASE DOCUMENT.AM_PM = "AM"
DOCUMENT.MILTIME = replacestr(DOCUMENT.TIME,":","")
CASE DOCUMENT.AM_PM = "PM" AND SUB(DOCUMENT.TIME,1,2) = 12
DOCUMENT.MILTIME = replacestr(DOCUMENT.TIME,":","")
CASE DOCUMENT.AM_PM = "PM"
DOCUMENT.MILTIME = replacestr(DOCUMENT.TIME,":","")
DOCUMENT.MILTIME = val(DOCUMENT.MILTIME) + val("1200")
ENDCOND
if (size(str(DOCUMENT.MILTIME))= 3) then
DOCUMENT.FORMATTED_MILTIME = "0" + str(DOCUMENT.MILTIME)
else
DOCUMENT.FORMATTED_MILTIME = str(DOCUMENT.MILTIME)
endif
DOCUMENT.timehold= (DOCUMENT.FORMATTED_MILTIME)
OBSNOW("FENTIV1TIME",document.timehold)
}
Also tested using PROCSTARTTI1 (no workie)
For testing I've used OBS Deathage DAD and it worked. Its like the fields meant for holding time won't take the military time format. Could that be? When they manually enter data now they use Military...
Thanks,