## Diff between Timestamp

IBM's cross-platform compiler PL/I for MVS, VM & VSE, OS/390 and Enterprise PL/I for z/OS

### Diff between Timestamp

Hi. How to get the difference between two timestamp in PL/I??
Shakthivel V

Posts: 22
Joined: Thu Mar 04, 2010 12:12 am
Has thanked: 0 time
Been thanked: 0 time

### Re: Diff between Timestamp

Are these DB2 timestamps?
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator

Posts: 3026
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

### Re: Diff between Timestamp

yes.. Its DB2 Timestamp only. but i need to check in my pli program .
Shakthivel V

Posts: 22
Joined: Thu Mar 04, 2010 12:12 am
Has thanked: 0 time
Been thanked: 0 time

### Re: Diff between Timestamp

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)
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator

Posts: 3026
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

### Re: Diff between Timestamp

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!
Robert AH Prins

prino

Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

### Re: Diff between Timestamp

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator

Posts: 3026
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times