[Migrated content. Thread originally posted on 05 April 2005]
Hello,
Does anyone have a quick routine for converting elapsed time to minutes & seconds? What I'm doing is accepting a beginning time and an ending time and subtracting the beginning from the ending time. How do I convert this result to minutes & seconds?
Thanks!
05 WS-TIME-START PIC 9(08) VALUE ZERO.
05 WS-TIME-START-1 REDEFINES WS-TIME-START.
10 WS-START-HOURS PIC 9(02).
10 WS-START-MINUTES PIC 9(02).
10 WS-START-SECONDS PIC 9(02).
10 FILLER PIC 9(02).
05 WS-TIME-STOP PIC 9(08) VALUE ZERO.
05 WS-TIME-STOP-1 REDEFINES WS-TIME-STOP.
10 WS-STOP-HOURS PIC 9(02).
10 WS-STOP-MINUTES PIC 9(02).
10 WS-STOP-SECONDS PIC 9(02).
10 FILLER PIC 9(02).
05 WS-TIME-ELAPSE PIC 9(08) VALUE ZERO.
05 WS-TIME-ELAPSE-1 REDEFINES WS-TIME-ELAPSE.
10 WS-ELAPSE-HOURS PIC 9(02).
10 WS-ELAPSE-MINUTES PIC 9(02).
10 WS-ELAPSE-SECONDS PIC 9(02).
10 FILLER PIC 9(02).
ACCEPT WS-TIME-STOP FROM TIME.
COMPUTE WS-TIME-ELAPSE = WS-TIME-STOP - WS-TIME-START.
IF WS-STOP-SECONDS >= WS-START-SECONDS
COMPUTE WS-ELAPSE-SECONDS = WS-STOP-SECONDS - WS-START-SECONDS
ELSE
IF WS-STOP-MINUTES = 0
SUBTRACT 1 FROM WS-STOP-HOURS
ADD 59 TO WS-STOP-MINUTES
ELSE
SUBTRACT 1 FROM WS-STOP-MINUTES
END-IF
COMPUTE WS-ELAPSE-SECONDS = 60 WS-STOP-SECONDS - WS-START-SECONDS.
IF WS-STOP-MINUTES >= WS-START-MINUTES
COMPUTE WS-ELAPSE-MINUTES = WS-STOP-MINUTES - WS-START-MINUTES
ELSE
SUBTRACT 1 FROM WS-STOP-HOURS
COMPUTE WS-ELAPSE-MINUTES = 60 WS-STOP-MINUTES - WS-START-MINUTES.
IF WS-STOP-HOURS >= WS-START-HOURS
COMPUTE WS-ELAPSE-HOURS = WS-STOP-HOURS - WS-START-HOURS
ELSE
COMPUTE WS-ELAPSE-HOURS = 24 WS-STOP-HOURS - WS-START-HOURS.
Regards,
Patty
[Migrated content. Thread originally posted on 05 April 2005]
Hello,
Does anyone have a quick routine for converting elapsed time to minutes & seconds? What I'm doing is accepting a beginning time and an ending time and subtracting the beginning from the ending time. How do I convert this result to minutes & seconds?
Thanks!
05 WS-TIME-START PIC 9(08) VALUE ZERO.
05 WS-TIME-START-1 REDEFINES WS-TIME-START.
10 WS-START-HOURS PIC 9(02).
10 WS-START-MINUTES PIC 9(02).
10 WS-START-SECONDS PIC 9(02).
10 FILLER PIC 9(02).
05 WS-TIME-STOP PIC 9(08) VALUE ZERO.
05 WS-TIME-STOP-1 REDEFINES WS-TIME-STOP.
10 WS-STOP-HOURS PIC 9(02).
10 WS-STOP-MINUTES PIC 9(02).
10 WS-STOP-SECONDS PIC 9(02).
10 FILLER PIC 9(02).
05 WS-TIME-ELAPSE PIC 9(08) VALUE ZERO.
05 WS-TIME-ELAPSE-1 REDEFINES WS-TIME-ELAPSE.
10 WS-ELAPSE-HOURS PIC 9(02).
10 WS-ELAPSE-MINUTES PIC 9(02).
10 WS-ELAPSE-SECONDS PIC 9(02).
10 FILLER PIC 9(02).
ACCEPT WS-TIME-STOP FROM TIME.
COMPUTE WS-TIME-ELAPSE = WS-TIME-STOP - WS-TIME-START.
IF WS-STOP-SECONDS >= WS-START-SECONDS
COMPUTE WS-ELAPSE-SECONDS = WS-STOP-SECONDS - WS-START-SECONDS
ELSE
IF WS-STOP-MINUTES = 0
SUBTRACT 1 FROM WS-STOP-HOURS
ADD 59 TO WS-STOP-MINUTES
ELSE
SUBTRACT 1 FROM WS-STOP-MINUTES
END-IF
COMPUTE WS-ELAPSE-SECONDS = 60 WS-STOP-SECONDS - WS-START-SECONDS.
IF WS-STOP-MINUTES >= WS-START-MINUTES
COMPUTE WS-ELAPSE-MINUTES = WS-STOP-MINUTES - WS-START-MINUTES
ELSE
SUBTRACT 1 FROM WS-STOP-HOURS
COMPUTE WS-ELAPSE-MINUTES = 60 WS-STOP-MINUTES - WS-START-MINUTES.
IF WS-STOP-HOURS >= WS-START-HOURS
COMPUTE WS-ELAPSE-HOURS = WS-STOP-HOURS - WS-START-HOURS
ELSE
COMPUTE WS-ELAPSE-HOURS = 24 WS-STOP-HOURS - WS-START-HOURS.
Regards,
Patty
[Migrated content. Thread originally posted on 05 April 2005]
Hello,
Does anyone have a quick routine for converting elapsed time to minutes & seconds? What I'm doing is accepting a beginning time and an ending time and subtracting the beginning from the ending time. How do I convert this result to minutes & seconds?
Thanks!
Another approach is to convert both the start and finish times to seconds (or hundredths of seconds), subtract, and then re-convert back to hours/mins/secs.
My example:
05 START-TIME.
10 START-HOURS PIC 99.
10 START-MINS PIC 99.
10 START-SECS PIC 99.
10 START-HDTHS PIC 99.
05 FINISH-TIME.
10 FINISH-HOURS PIC 99.
10 FINISH-MINS PIC 99.
10 FINISH-SECS PIC 99.
10 FINISH-HDTHS PIC 99.
05 START-NUM PIC 9(9).
05 FINISH-NUM PIC 9(9).
......
ACCEPT START-TIME FROM TIME.
...[do something here] ....
ACCEPT FINISH-TIME FROM TIME.
IF FINISH-TIME
ADD 24 TO FINISH-HOURS
END-IF.
COMPUTE START-NUM = START-HDTHS
(START-SECS * 100)
(START-MINS * 6000)
(START-HOURS * 360000).
COMPUTE FINISH-NUM = FINISH-HDTHS
(FINISH-SECS * 100)
(FINISH-MINS * 6000)
(FINISH-HOURS * 360000).
SUBTRACT START-NUM FROM FINISH-NUM.
DIVIDE FINISH-NUM BY 100
GIVING FINISH-NUM REMAINDER FINISH-HDTHS.
DIVIDE FINISH-NUM BY 60
GIVING FINISH-NUM REMAINDER FINISH-SECS.
DIVIDE FINISH-NUM BY 60
GIVING FINISH-NUM REMAINDER FINISH-MINS.
DIVIDE FINISH-NUM BY 24
GIVING FINISH-NUM REMAINDER FINISH-HOURS.
Of course at the end FINISH-NUM should be zero (number of days), and the FINISH-TIME contains your elapsed time.
This assumes (as does the previous post) that your elapsed time will never be greater than 24 hours.
Hope this helps.
Cheers