Page 1 of 1

Diff between Timestamp

PostPosted: Tue Aug 10, 2010 2:35 pm
by Shakthivel V
Hi. How to get the difference between two timestamp in PL/I??

Re: Diff between Timestamp

PostPosted: Wed Aug 11, 2010 1:49 am
by NicC
Are these DB2 timestamps?

Re: Diff between Timestamp

PostPosted: Wed Aug 11, 2010 2:30 pm
by Shakthivel V
yes.. Its DB2 Timestamp only. but i need to check in my pli program .

Re: Diff between Timestamp

PostPosted: Wed Aug 11, 2010 4:41 pm
by NicC
I think you can use the DAYS builtin function - convert both, subtract and then another BIF (same section of the manual) to convert the result back to time. Something like

diff = days(ts1) - days(ts2)
ans = ????(diff)

Re: Diff between Timestamp

PostPosted: Wed Aug 11, 2010 8:29 pm
by prino
NicC wrote:I think you can use the DAYS builtin function - convert both, subtract and then another BIF (same section of the manual) to convert the result back to time. Something like

diff = days(ts1) - days(ts2)
ans = ????(diff)


Don't "think you can use", if you had RFTM, you would have known that the DAYS builtin is useless for DB2 timestamps, none of the PL/I builtin functions supports the "YYYYMMDDHHMISS999999" format of DB2 timestamps!

You need extended float (i.e. FLOAT DEC (33), or FLOAT DEC(34) for DFP)) to cater for the full range of self-calculated microseconds, unless you split it in date and time parts, in which case you still have to handle the micro-second part yourself!

Re: Diff between Timestamp

PostPosted: Wed Aug 11, 2010 8:48 pm
by NicC
Good catch - I only glanced at the manual. One can always drop off the microseconds unless it is so really important but that is the analyst's call.