How can I calculate the elapsed time between a starting time and an ending time?

Document ID : KB000047638
Last Modified Date : 14/02/2018
Show Technical Document Details

Question: 

Add Content How can I calculate the elapsed time between a starting time and an ending time?

 

Environment:  

CA Easytrieve Report Generator, release 11.6

Answer: 

Using the following as input: 

//TIMECARD DD * 
001504 024504 
191504 211402 
/* 

these are the results:
*** START 00:15:04 
*** END 02:45:04 
*** DURATION 02:30:00 
*** START 19:15:04 
*** END 21:14:02 
*** DURATION 01:58:58 

FILE TIMECARD 
TC_START 1 6 N 
TC_END 9 6 N 
* 
WK_ST_SECONDS S 9 P 0 
WK_ND_SECONDS S 9 P 0 
WK_SECONDS S 9 P 0 
* 
WS_ST_TIME S 6 N MASK ('99:99:99') 
WS_ST_HOURS WS_ST_TIME 2 N 
WS_ST_MINUTES WS_ST_TIME +2 2 N 
WS_ST_SECONDS WS_ST_TIME +4 2 N 
* 
WS_ND_TIME S 6 N MASK ('99:99:99') 
WS_ND_HOURS WS_ND_TIME 2 N 
WS_ND_MINUTES WS_ND_TIME +2 2 N 
WS_ND_SECONDS WS_ND_TIME +4 2 N 
* 
WS_PERIOD S 6 N MASK ('99:99:99') 
WS_HOURS WS_PERIOD 2 N 
WS_MINUTES WS_PERIOD +2 2 N 
WS_SECONDS WS_PERIOD +4 2 N 
* 
JOB INPUT TIMECARD START PROLOG FINISH EPILOG NAME TIMEDIFF 
* 
IF TC_START NOT NUMERIC 
DISPLAY '*** INVALID STARTING TIME *** ' TC_START 
GO TO JOB 
END-IF 
* 
IF TC_END NOT NUMERIC 
DISPLAY '*** INVALID ENDING TIME *** ' TC_END 
GO TO JOB 
END-IF 
* 
IF TC_END < TC_START 
DISPLAY '*** ENDING TIME PRIOR TO STARTING TIME *** ' + 
TC_END ' < ' TC_START 
GO TO JOB 
END-IF 
WS_ST_TIME = TC_START 
WS_ND_TIME = TC_END 
* 
PERFORM TIMECALC 
DISPLAY '*** START ' WS_ST_TIME 
DISPLAY '*** END ' WS_ND_TIME 
DISPLAY '*** DURATION ' WS_PERIOD 
* 
PROLOG. PROC 
END-PROC 
* 
EPILOG. PROC 
END-PROC 
* 
TIMECALC. PROC 
WK_ST_SECONDS = 3600 * WS_ST_HOURS + 60 * WS_ST_MINUTES + WS_ST_SECONDS 
WK_ND_SECONDS = 3600 * WS_ND_HOURS + 60 * WS_ND_MINUTES + WS_ND_SECONDS 
WK_SECONDS = WK_ND_SECONDS - WK_ST_SECONDS 
WS_HOURS = WK_SECONDS / 3600 
WS_MINUTES = (WK_SECONDS - WS_HOURS * 3600) / 60 
WS_SECONDS = WK_SECONDS - WS_HOURS * 3600 - WS_MINUTES * 60 
END-PROC 
/* 
//EZTP.TIMECARD DD * 
001504 024504 
191504 211402 
/* 
//
 

Additional Information:

 

The above coding used to calculate the time from the starting time to the ending time works as long as both times are in the same day and the start time is always less than the end time in the same business day.  Otherwise, you may take into account that a period of time may go across midnight, there must be an indicator coded that will show whether starting time and ending times are on the same day or a different day.  Any modifications needed for the above program are up to the client to make the program modifications.