Calculate duration of start-stop time

rbaggetta

New Member
I'm trying to caculate the number of minutes a program runs as its updating a table to see how long it takes the database to make them. I know Progress stores it in secods or miliseconds...but if I try to subtract start from end, doesn't add up.

ie: start time 13:00:00, and end time is 14:30:30, I should get a result of 1:30:30.

thanks to anyone who can answer this one.
 

FrancoisL

Member
DEF VAR iStart AS INT.
DEF VAR iEnd AS INT.


iStart = TIME.
RUN Proc.
iEnd = TIME.


MESSAGE STRING(iEnd - iStart, "HH:MM:SS").


You can also use ETIME if your progress version supports it.

ETIME(true).
RUN Proc.
iElapse = ETIME.
MESSAGE STRING(iElapse, "HH:MM:SS").
 

Cecil

19+ years progress programming and still learning.
If you are using OE 10.1B you could use the following function:

Code:
DEFINE VARIABLE dtDataTimeStart AS DATETIME NO-UNDO.
DEFINE VARIABLE dtDataTimeEnd   AS DATETIME NO-UNDO.
DEFINE VARIABLE dtTotalTime       AS INT64 NO-UNDO.

dtDataTimeStart = NOW.

/*
  TRANSACTION BLOCK:
  RUN blar blar.
*/

dtDataTimeEnd = NOW.

dtTotalTime = INTERVAL(dtDataTimeEnd, dtDataTimeStart, /*'years' 'months' 'weeks' 'days' 'hours' 'minutes' 'seconds'*/ 'milliseconds' ).

MESSAGE STRING(dtTotalTime).
This sample code is very good if your process/transaction spans over midnight or more than one day.
 

rbaggetta

New Member
Thanks, but I think I didn't clearify what I was asking for. I don't need to know how long the transaction runs within the actual program itself, rather, when it does run, the system stores the date/time on each transaction from begining to end. Example:
abc 10:09:00
def 10:14:05
ghi 10:30:05
jkl 10:31:03
mno 10:31:45
pqr 10:33:00
============
Total of time between "abc" and "pqr" = xx : xx :xx

Its more of a report based on what happened to see how much time it took to make it from "abc" to "pqr"...in this case, like 24 min +/-.
 

FrancoisL

Member
Here a procedure that will calculate the time difference between 2 INPUT time in HH:MM:SS format and send it back in HH:MM:SS format.

Code:
PROCEDURE CalcTimeDiff :
   DEF INPUT PARAMETER pcStartTime AS CHAR.  /* HH:MM:SS format */
   DEF INPUT PARAMETER pcEndTime AS CHAR.  /* HH:MM:SS format */
   DEF OUTPUT PARAMETER pcElapseTime AS CHAR.  /* HH:MM:SS format */

   DEF VAR iStartTime AS INT.
   DEF VAR iEndTime AS INT.
   DEF VAR iElapseTime AS INT.

   /* Convert to Progress INT based time */

   iStartTime = ( INT(ENTRY(1,pcStartTime,':')) * 3600 ) + 
                    ( INT(ENTRY(2,pcStartTime,':')) * 60) + 
                     INT(ENTRY(3,pcStartTime,':')).

   iEndTime = ( INT(ENTRY(1,pcEndTime,':')) * 3600 ) + 
                    ( INT(ENTRY(2,pcEndTime,':')) * 60) + 
                     INT(ENTRY(3,pcEndTime,':')).


    IF iEndTime < iStartTime THEN  /* End Time is on next day */
       iEndTime = iEndTime + 86400. 

   iElapseTime = iEndTime - iStartTime.

   /* Convert Result to HH:MM:SS format */
   pcElapseTime = STRING(iElapseTime, "HH:MM:SS").
   
END PROCEDURE.

This should help you for your report.
 

rbaggetta

New Member
FrancoisL, thanks, with some minor changes I got it to run..this is one for my books...nice function btw...
 
Top