It seems like this should be easier to find, but how do you retrieve the system time? Manuals keep directing me to %time and %timstamp, but it looks like those are for converting and not retrieving. Can anyone help me on this?
Announcement
Collapse
No announcement yet.
retrive Current time
Collapse
X
-
Re: retrive Current time
time = %time()
timestamp = %timestamp()Code:cmdstring = 'sndmsg Msg(' + Q + 'The Time is ' + %char(%time()) + Q + ')' + ' tousr(' + %trim(workuser) + ')'
Code:* * Field Definitions. * d ISOdate s d d ISOtime s t d thestamp s z *============================================================= * M A I N L I N E *============================================================= c eval thestamp = %timestamp() c eval ISODate = %date(thestamp) c eval ISOtime = %time(thestamp) c c eval *inlr = *on
Code:* * Field Definitions. * d TimeX s T d TimeDec s 6 0 *============================================================= * M A I N L I N E *============================================================= * c eval Timex = %time() c eval TimeDec = %uns(%char(%Time():*HMS0)) * c eval *inlr = *on *
Code:// calculate where we are in the day and put that in as a decimal hour = %subdt(%time():*hours); select; when hour <= 8; hour = 1; when hour <= 9; hour = 2; when hour <= 10; hour = 3; when hour <= 11; hour = 4; when hour <= 12; hour = 5; when hour <= 13; hour = 6; when hour <= 14; hour = 7; when hour <= 15; hour = 8; when hour <= 16; hour = 8; when hour <= 17; hour = 8; endsl; MTDDAYS += (hour/8); if MTDDAYS < 1; MTDDAYS = 1; endif;All my answers were extracted from the "Big Dummy's Guide to the As400"
and I take no responsibility for any of them.
www.code400.com
Comment
-
Re: retrive Current time
A couple of different methods:
1) If you are running a report, can use the D-Specs. This method gives you the time when the program starts. Note that the Time Format can be several different types (*HMS, *ISO, *USA, *EUR, *JIS).
2) Free form method:Code:D XTime S T TimFmt(*ISO) Inz(*Sys)
3) Fixed format method:Code:/free XTime = %TIME(); /end-free
Code:* OpCode Result Field C Time XTimeLast edited by Chipper; January 9, 2009, 02:42 PM.
Comment
-
Re: retrive Current time
Here's one way to do it:
Code:d fieldx s 6s 0 /free fieldx = %dec( %time : *HMS ) ; dsply %editc( fieldx : 'X' ); return;
And a longer version:
Code:d fieldx s 6s 0 /free fieldx = %dec( %subdt( %time : *hours ) : 2 : 0) *10000 + %dec( %subdt( %time : *minutes ) : 2 : 0) *100 + %dec( %subdt( %time : *seconds ) : 2 : 0) ; dsply %char( fieldx ); return;Last edited by MichaelCatalani; January 10, 2009, 12:23 AM.Michael Catalani
IS Director, eCommerce & Web Development
Acceptance Insurance Corporation
www.AcceptanceInsurance.com
www.ProvatoSys.com
Comment







Comment