Focal Point
Military Time

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3701048331

March 11, 2005, 02:06 PM
Prarie
Military Time
Anyone know a routine to convert Military time to AM/PM. The only thing I've been able to find is a routine that takes the System Time and I can't seem to trick into taking my field instead of the System Time.
Here's the routine that does that.
CURRENT_TIME2/HHISA= HGETC(8,'HHISA');

I just have a field that is Time/A8 - 13:00:00 and I need it to print 01:00:00AM

Thanks

Prarie
March 11, 2005, 03:26 PM
Leah
First off on the 24 hour clock, 13:00 is 1:00 PM sorry couldn't resist.

I looked through functions and found nothing, but:

Check if you first field is gt 12 if it is then subtract 12 from it and put the PM on the end.

Of course first you'd have to convert the first two digits to a number using EDIT then tack it all back when complete.

HDIG/I2 = EDIT (TMFLD,'99');
HDIG/I2 = IF HDIG GT 12 THEN HDIG - 12 ELSE HDIG;
ADIG/A2 = EDIT(HDIG);
AMPM/A2 = IF HDIG GT 12 THEN 'PM' ELSE 'AM';
NEWTIME/A10 = ADIG | EDIT (MFLD,'$$999999') | APPM;

Of course the above hasn't been syntax checked. And what happens if it is 24:00:00, or is it 00:00:00 for midnight on the sytem? Also, for 12:00:00 which is noon do you code it as am or pm.

Such a tangled web when you start discussing how to do time.
March 11, 2005, 03:37 PM
Prarie
Yes...it would be PM..;-)

I just had figured out this...which is basically what you were saying...after I figured there just was not going to be a neat function to do this for me. Now they have one that converts time to Midnight - HMIDNT...but not Military time go figure.

HRS1/I2 = EDIT(HRS);
HRS2/I2 = IF HRS1 GT 12 THEN HRS1 - 12 ELSE HRS1;
HRS3/A2 = EDIT(HRS2);
AM/A2 = IF HRS1 GT 12 THEN 'PM' ELSE 'AM';

NEWTIME/A7 = HRS3 | ':' | MIN | AM;
March 11, 2005, 07:48 PM
susannah
&TOD
is the system variable that prints in 24hour time. 13.40.55 is 1:40 and 55 secs .
Do you have timestamps as data fields in a file that you have to work with? or are you starting from scratch with system time?
I thought military time was gmt always, regardless of where you were in the world.
We have a way to extract your gmt offset from your reg.exe, if you're going that route.
(nb: win2k server)
March 11, 2005, 08:50 PM
Prarie
No actually this is a time field that is stored I4 on a Help Call Center file, as a time a call was recorded. So it reads 0245...that is really saying 2:45...and 1300 is 13:00. So had to take and split into two. Rightside - Leftside.. concatenate it in to a Military time ...have no clue why it is like this...but that's what I have to work with...so I've converted it to a time and then did the little routine above...and seems to be working...
Hope that makes sense.
March 14, 2005, 07:03 PM
TexasStingray
Try This


NEWTIMEI4/I4 = IF TIMEFIELD GE 1300 THEN TIMEFIELD - 1200 ELSE TIMEFIELD;
NEWTIMEA4/A4 = EDIT(NEWTIMEI4);
NEWTIME/A8 = IF TIMEFIELD LT 1000 THEN EDIT(NEWTIMEA4, ' $9:99 AM') ELSE
IF TIMEFIELD LT 1200 THEN EDIT(NEWTIMEA4, '99:99 AM') ELSE
IF TIMEFIELD LT 1300 THEN EDIT(NEWTIMEA4, '99:99 PM') ELSE
IF TIMEFIELD LT 2000 THEN EDIT(NEWTIMEA4, ' $9:99 PM') ELSE
EDIT(NEWTIMEA4, '99:99 PM');
Don't know of any function but this should work replace TIMEFIELD with your actual field.

This message has been edited. Last edited by: <Mabel>,
March 14, 2005, 08:41 PM
Prarie
I like that...Thanks...
March 16, 2005, 01:51 PM
c. jenks
susannah said:
quote:
I thought military time was gmt always, regardless of where you were in the world.
Actually military time is no longer done on gmt, its now based on zulu. I believe thats because gmt uses day light savings and the other does not.

The bigger question is does he mean military time, set to zulu or the 24 hour clock, which was created by miners.

Sorry I couldn't resist.
March 16, 2005, 02:08 PM
<JG>
Zulu and GMT are exactly the same thing the only difference is that GMT is the common mans name and Zulu is the Military name.

I quote from http://wwp.greenwichmeantime.com

'"Zulu" time is that which is more commonly know as "GMT"'
April 04, 2008, 09:27 AM
LOgle
My timefield is format of Char 8 in the real database. I am trying to use this suggestion but it is not working. Any suggestions?
NEWTIMEI4/I4 = IF TIMEFIELD GE 1300 THEN TIMEFIELD - 1200 ELSE TIMEFIELD;
NEWTIMEA4/A4 = EDIT(NEWTIMEI4);
NEWTIME/A8 = IF TIMEFIELD LT 1000 THEN EDIT(NEWTIMEA4, ' $9:99 AM') ELSE
IF TIMEFIELD LT 1200 THEN EDIT(NEWTIMEA4, '99:99 AM') ELSE
IF TIMEFIELD LT 1300 THEN EDIT(NEWTIMEA4, '99:99 PM') ELSE
IF TIMEFIELD LT 2000 THEN EDIT(NEWTIMEA4, ' $9:99 PM') ELSE
EDIT(NEWTIMEA4, '99:99 PM');


V. 762
Windows XP
April 07, 2008, 09:59 AM
PBrightwell
TIME1 is just to get a time in the 8 CHAR format in your database. If it is actually HH:MM:SS then the edit for TIME2A needs to be (TIME1,'99$99').

DEFINE FILE CAR
TIME1/A8='13240000';
TIME2A/A4=EDIT(TIME1,'9999');
TIME2/I4=EDIT(TIME2A);
TIME3/I4=IF TIME2 GE 1300 THEN TIME2-1200;
END

TABLE FILE CAR
PRINT TIME1 TIME2 TIME3
BY CAR
END


Pat
WF 7.6.8, AIX, AS400, NT
AS400 FOCUS, AIX FOCUS,
Oracle, DB2, JDE, Lotus Notes
April 07, 2008, 01:49 PM
Glenda
I like this too with one minor change.

quote:
IF TIMEFIELD LT 2000 THEN EDIT(NEWTIMEA4, ' $9:99 PM') ELSE

quote:
NEWTIMEI4/I4 = IF TIMEFIELD GE 1300 THEN TIMEFIELD - 1200 ELSE TIMEFIELD;
NEWTIMEA4/A4 = EDIT(NEWTIMEI4);
NEWTIME/A8 = IF TIMEFIELD LT 1000 THEN EDIT(NEWTIMEA4, ' $9:99 AM') ELSE
IF TIMEFIELD LT 1200 THEN EDIT(NEWTIMEA4, '99:99 AM') ELSE
IF TIMEFIELD LT 1300 THEN EDIT(NEWTIMEA4, '99:99 PM') ELSE
IF TIMEFIELD LT 2000 THEN EDIT(NEWTIMEA4, ' $9:99 PM') ELSE
EDIT(NEWTIMEA4, '99:99 PM');


IF TIMEFIELD LT 2000 THEN EDIT(NEWTIMEA4, ' $9:99 PM') ELSE

should be 2200 not 2000.


Glenda

In FOCUS Since 1990
Production 8.2 Windows
April 08, 2008, 08:49 AM
PBrightwell
Come on Glenda, make him do a little bit of work!


Pat
WF 7.6.8, AIX, AS400, NT
AS400 FOCUS, AIX FOCUS,
Oracle, DB2, JDE, Lotus Notes
April 08, 2008, 09:10 AM
Glenda
Pat,

Normally I would agree with you. But this is Prairie and "she" has helped me many a time. Turn about fair play in this instance.


Glenda

In FOCUS Since 1990
Production 8.2 Windows
April 08, 2008, 09:48 AM
Prarie
awwww Thanks...how nice. This was originally posted by me in 2005...and LOgle did their search...and was asking another quetion. But I did go back and look at my program...to make sure I had the correct number Glenda!!


In Focus since 1993. WebFOCUS 7.7.03 Win 2003