View previous topic :: View next topic |
Author |
Message |
MikeMara Beginner
Joined: 09 Oct 2006 Posts: 6 Topics: 2 Location: Tampa, Florida
|
Posted: Mon Oct 09, 2006 6:59 pm Post subject: Date/Time Calculation |
|
|
Can anyone provide me with a Rexx code to display the number of hours||minutes||seconds from 2 dates and times? |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
MikeMara Beginner
Joined: 09 Oct 2006 Posts: 6 Topics: 2 Location: Tampa, Florida
|
Posted: Tue Oct 10, 2006 11:20 am Post subject: |
|
|
Actually, I saw this website, but it executes more than what I available on the mainframe. I tried coding the pieces I could use, but it was not enough. |
|
Back to top |
|
 |
superk Advanced

Joined: 19 Dec 2002 Posts: 684 Topics: 5
|
Posted: Thu Oct 12, 2006 2:10 pm Post subject: |
|
|
I'm still developing this bit of code, I have some issues with rounding, but maybe it'll help you get started:
Code: |
/* REXX DATEDIFF */
Numeric Digits 13
fromdate = '01/01/06'
fromtime = '00:00:00'
todate = '10/12/06'
totime = '15:03:00'
fromdate_b = Date(B,fromdate,U)
todate_b = Date(B,todate,U)
Say 'DATEDIFF' fromdate fromdate_b fromtime '-' todate todate_b totime
ndays = todate_b - fromdate_b
fulldays = 0
If ndays > 1 Then fulldays = (ndays - 1) * 86400
Parse Var fromtime hh ':' mm ':' ss .
fromtime_e = (hh * 3600) + (mm * 60) + ss
fromtime_ss = 86400 - fromtime_e
Parse Var totime hh ':' mm ':' ss .
totime_ss = (hh * 3600) + (mm * 60) + ss
total_ss = fromtime_ss + fulldays + totime_ss
If total_ss >= 86400 Then
Do
days = (total_ss % 86400)
End
Else days = 0
If total_ss - (days * 86400) >= 3600 Then
Do
hours = ((total_ss - (days * 86400)) % 3600)
End
Else hours = 0
If total_ss - (hours * 3600) - (days * 86400) >= 60 Then
Do
minutes = ((total_ss - (hours * 3600) - (days * 86400)) % 60)
End
Else minutes = 0
seconds = total_ss - (minutes * 60) - (hours * 3600) - (days * 86400)
Say Right('Days',4)' 'Right('Hours',5)||,
' 'Right('Minutes',7)' 'Right('Seconds',7)
Say Right(days,4,'0')' 'Right(hours,5,'0')||,
' 'Right(minutes,7,'0')' 'Right(seconds,7,'0')
|
|
|
Back to top |
|
 |
MikeMara Beginner
Joined: 09 Oct 2006 Posts: 6 Topics: 2 Location: Tampa, Florida
|
Posted: Fri Oct 13, 2006 6:32 am Post subject: |
|
|
Thank-you very much for the sample! I tried it and so far the results seem to be accurate. |
|
Back to top |
|
 |
MikeMara Beginner
Joined: 09 Oct 2006 Posts: 6 Topics: 2 Location: Tampa, Florida
|
Posted: Thu Oct 19, 2006 10:19 am Post subject: |
|
|
I tried different scenarios with your code and found 1 issue. Days = 1 with the following dates/times. It should equal 0.
Fromdate = 10/19/2006
Fromtime = 11:08:00
ToDate = 10/19/2006
ToTime = 11:18:00 |
|
Back to top |
|
 |
|
|