How to Calculate Lapse Time

15 pts.
Tags:
Lapse Time Calculation
RPG
SUBDUR
Hi Everyone: Is there an easy way to calculate the lapse time between 2 timestamps? The SUBDUR returns either in HR/MI/or SECONDS. But I want the lapse time in HHMMSS. Can it be done without much coding? Thanks in advance.
ASKED: March 1, 2008  7:57 PM
UPDATED: April 8, 2010  3:37 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Simply take the duration in seconds and divide by the number of seconds in a day to get the number of days. Take the remainder, divide by seconds in a hour to get the number of hours. Take the remainder, divide by seconds in a minute to get the number of minutes. Take the remainder and you have the number of seconds.

To me this is not much coding and is easy, for someone who has to pick up your code later, for others to follow.

You could play a “trick” in that if you know <b>with absolute certainty, and for all of time,</b> that the duration is always less than 24 hours then you add the duration to a time field initialized to 00.00.00, but this is really playing games — something to be avoided as it’s sure to mislead someone in the future. Less code for you now is not a good trade off for lots of debug time in the future…

Bruce Vining
<a href=”http://www.brucevining.com/”>http://www.brucevining.com/</a>
Integrated solutions for the System i user community

Try this VBScript code for some ideas, basically it returns the number of seconds between the two <i>time stamps</i>.

<pre>Option Explicit

Dim Start

Start = GetTime()
‘ your code here
wscript.sleep (10000)
‘end your code
WScript.Echo “Your code took ” & GetTimeDifference(Start) & ” seconds to complete.”
WScript.Quit

Function GetTime()
GetTime = Now()
End Function

Function GetTimeDifference(Start)
GetTimeDifference = (Now() – Start)*1000 ‘return the number of seconds
End Function</pre>

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Jerry Lees
    The VBScript code I posted in the answer should get you started. Obviously it's not fully regression tested... etc etc... be sure and test in your environment and all that jazz. ;-) Be sure and check out my blog here on ITKE for more Network administration and VBSCRIPT tips. The VBScript Network and Systems Administrator's Cafe
    5,335 pointsBadges:
    report
  • Gilly400
    Hi, You could also use a bit of embedded SQL to do your calculation for you :- C/EXEC SQL C+ SET :DUR = TIME(:ENDTIME) - :STRTIME C/END-EXEC This should give you a duration in the format of HHMMSS in the field DUR (6,0). Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • Sloopy
    Bruce Vining's answer is good; it doesn't take much code, if you use BIFs, and it's clear. I find I'm writing more RPGLE with embedded SQL nowadays, but I certainly wouldn't embed SQL into RPG just to calculate a duration. Probably a reuseable solution is best - a procedure in your general-purpose service program (which I am sure you have) to return the duration in the requested format. Sloopy
    2,195 pointsBadges:
    report
  • TomLiotta
    I certainly wouldn’t embed SQL into RPG just to calculate a duration. Why not? Embedded SQL can frequently be the best solution. Probably a reuseable solution is best - a procedure in your general-purpose service program (which I am sure you have) to return the duration in the requested format. SQL can also frequently provide the most reusable solution. A stored proc can become 'reusable' even to remote clients. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following