Page 1 of 1

Formatting Time

PostPosted: Mon Dec 21, 2015 7:19 am
by tcpipman
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"

Re: Formatting Time

PostPosted: Mon Dec 21, 2015 5:28 pm
by Akatsukami
I believe that rather than 2,0,0,0 you want 2,2,0,0.

Re: Formatting Time

PostPosted: Mon Dec 21, 2015 8:35 pm
by Mickeydusaor
or say "Time is "right(hours,2,'0')":"right(minutes,2,'0')":"right(seconds,2,'0')

Re: Formatting Time

PostPosted: Mon Dec 21, 2015 11:50 pm
by tcpipman
The 2,2,0,0 .. ended up adding to decimal points behind the number .. IE
Hours that was 4 .. become 4.00

Re: Formatting Time

PostPosted: Tue Dec 22, 2015 2:05 am
by enrico-sorichetti
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

Re: Formatting Time

PostPosted: Wed Jan 06, 2016 1:47 am
by tcpipman
Thank you so much .. that worked great.