IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Timestamp calculation.


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
saubhik

New User


Joined: 21 Sep 2007
Posts: 35
Location: kolkata

PostPosted: Thu Jun 17, 2010 10:50 pm
Reply with quote

Hi All,

My requirement is to calculate the difference between the two db2 table timestamp is 48 hours or not.

We have to fields

1. current timestamp. char(26)
2. created timestamp.char(26)
I need to find out the difference between these 2 fields is greater than 48 hours or 2 days or not.

Please let me know how to calculate this.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu Jun 17, 2010 10:53 pm
Reply with quote

Quote:
Please let me know how to calculate this.
In Assembler or PL/I?
Back to top
View user's profile Send private message
saubhik

New User


Joined: 21 Sep 2007
Posts: 35
Location: kolkata

PostPosted: Thu Jun 17, 2010 10:56 pm
Reply with quote

In PL1
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Thu Jun 17, 2010 11:16 pm
Reply with quote

Do you know the format?

If not, then you are sunk.

If so, then can you calculate the number of hours, minutes, or seconds each is, and then maybe subtract, and then maybe compare?
Back to top
View user's profile Send private message
saubhik

New User


Joined: 21 Sep 2007
Posts: 35
Location: kolkata

PostPosted: Thu Jun 17, 2010 11:20 pm
Reply with quote

I know the format of timestamp.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jun 17, 2010 11:22 pm
Reply with quote

since you are talking about 2 days,
simply extract the date portion,
populating a field that will work with the DAYS intrinsic function, see the example at bottom of page,

then add 2 days. reformat to your timestamp format and compare.

a wander thru the PL1 reference manual is all it takes,
unless of course all you want is someone to provide the code for you.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Thu Jun 17, 2010 11:24 pm
Reply with quote

methinks we need more resolution - 48 hours is really the requirement
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jun 17, 2010 11:27 pm
Reply with quote

Phrzby Phil wrote:
methinks we need more resolution - 48 hours is really the requirement


good chance. if so, he only needs to research the manual a little more.
Back to top
View user's profile Send private message
saubhik

New User


Joined: 21 Sep 2007
Posts: 35
Location: kolkata

PostPosted: Thu Jun 17, 2010 11:27 pm
Reply with quote

yes.48 hours calculation is actual requirement.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Thu Jun 17, 2010 11:28 pm
Reply with quote

We look forward to your solution, based on ample suggestions above.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jun 18, 2010 1:17 am
Reply with quote

Phrzby Phil wrote:
methinks we need more resolution - 48 hours is really the requirement


good one, had me going for a few minutes.

as in what is the difference between 48 hrs and 2 days?
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Jun 18, 2010 1:25 am
Reply with quote

Quote:
as in what is the difference between 48 hrs and 2 days?

yyyymm03235900 - yyyymm01000100 = 2 days or almost 72 hours...
yyyymm03000100 - yyyymm01235900 = 2 days or just over 24 hours...
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jun 18, 2010 1:29 am
Reply with quote

I should not have smoked that thing!
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Jun 18, 2010 1:38 am
Reply with quote

dbzTHEdinosauer wrote:
I should not have smoked that thing!
Not so, it sometimes helps...grin....
FWIW, a quick subtraction of just the days to determine if the difference is equal to two before the more involved hour calculation might save significant time if the difference is usually less than one ore greater than three.
Back to top
View user's profile Send private message
saubhik

New User


Joined: 21 Sep 2007
Posts: 35
Location: kolkata

PostPosted: Fri Jun 18, 2010 10:56 am
Reply with quote

Solution is geiven below.Let me know if it is correct or not.

hours_difference = (days difference)*24 + hours difference + (minutes difference) / 60
=[days (current tmstmp) - days (last_timestamp))] *24 +
[Hour(current tmstmp) - Hour(last_timestamp)] +
[Minute(current tmsmp) - Minute(last_timestamp)]/60
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Jun 18, 2010 5:17 pm
Reply with quote

We don't need to let you know - just test it on an appropriate set of values.

Some will be exactly 48 hours, some a second longer, some shorter, etc. etc. etc.

Even test with the timestamps in the wrong order - do you test for this and generate an error message?

Designing test data is part of a programmer's responsibility.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Jun 18, 2010 5:18 pm
Reply with quote

Dick -

Don't worry about it. You get up 6-7 hours before I do, so mistakes will happen.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
No new posts Insert system time/date (timestamp) u... DFSORT/ICETOOL 5
No new posts Timestamp difference and its average ... DB2 11
No new posts Allocated space calculation from DCOL... PL/I & Assembler 3
Search our Forums:

Back to Top