Formatting Time



IBM's Command List programming language & Restructured Extended Executor

Formatting Time

Postby tcpipman » Mon Dec 21, 2015 7:19 am

I am attempting to take an SMF binary time field that counts from midnight in 100th of seconds. I was able to break down the time to hours, minutes and seconds however when I go to print it I lose leading 0s if the time is less then 10. I tried to use the format command but it did not work.. any hints on how to do this.

85 *-* start_time = C2D(SUBSTR(SMFRECORD.3,C2D(S1R)-3+96,4))
86 *-* say "START time is " start_time
START time is 1490447
87 *-* time_var = start_time/(60*60*100)
88 *-* parse var time_var hours "." extra
89 *-* time_var = (start_time/(60*100)) - hours*60
90 *-* parse var time_var minutes "." extra
91 *-* time_var = (start_time/(100)) - (hours*3600 + minutes *60)
92 *-* parse var time_var seconds "." extra
93 *-* say "Time is "format(hours,2,0,'0','0')":"format(minutes,2,0,0,0)":"format(seconds,2,0,0,0)
Time is 4: 8:24
94 *-* "EXECIO 0 DISKR IN (FINIS"
>>> "EXECIO 0 DISKR IN (FINIS"
tcpipman
 
Posts: 18
Joined: Tue Sep 22, 2015 2:03 pm
Has thanked: 4 times
Been thanked: 0 time

Re: Formatting Time

Postby Akatsukami » Mon Dec 21, 2015 5:28 pm

I believe that rather than 2,0,0,0 you want 2,2,0,0.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Formatting Time

Postby Mickeydusaor » Mon Dec 21, 2015 8:35 pm

or say "Time is "right(hours,2,'0')":"right(minutes,2,'0')":"right(seconds,2,'0')
User avatar
Mickeydusaor
 
Posts: 29
Joined: Fri Feb 24, 2012 11:24 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Formatting Time

Postby tcpipman » Mon Dec 21, 2015 11:50 pm

The 2,2,0,0 .. ended up adding to decimal points behind the number .. IE
Hours that was 4 .. become 4.00
tcpipman
 
Posts: 18
Joined: Tue Sep 22, 2015 2:03 pm
Has thanked: 4 times
Been thanked: 0 time

Re: Formatting Time

Postby enrico-sorichetti » Tue Dec 22, 2015 2:05 am

smftime = 1490447

hh =   ( smftime %  100 ) %  3600
mm = ( ( smftime %  100 ) // 3600 ) % 60
ss = ( ( smftime %  100 ) // 3600 ) // 60
hds =  ( smftime // 100 )

say hh mm ss hds
say right(hh,2,"0")":"right(mm,2,"0")":"right(ss,2,"0")


works for me

04:08:24


the snippet is meant to show a better alternative to parse the timestamp
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

These users thanked the author enrico-sorichetti for the post:
tcpipman (Wed Jan 06, 2016 1:46 am)
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Formatting Time

Postby tcpipman » Wed Jan 06, 2016 1:47 am

Thank you so much .. that worked great.
tcpipman
 
Posts: 18
Joined: Tue Sep 22, 2015 2:03 pm
Has thanked: 4 times
Been thanked: 0 time


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post