Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Computing Time Difference

Status
Not open for further replies.

jerold

Programmer
Aug 30, 2000
52
0
0
PH
Does anybody know a code on how to get the difference of the system time in batch?

e.g.

ACCEPT WS-START-TIME FROM TIME.
ACCEPT WS-END-TIME FROM TIME.

Then I want to get the difference of the
end and start time and put it the difference
in hh:mm:ss format.

thanks a lot!
 
(assuming the end-date is the same as the starting date)

Code:
01  WS-TIMES.
    03  WS-START-TIME PIC 9(06).
    03  WS-START-TIME-R REDEFINES WS-START-TIME.
        05  WS-START-TIME-H  PIC 9(02).
        05  WS-START-TIME-M  PIC 9(02).
        05  WS-START-TIME-S  PIC 9(02).
    03  WS-END-TIME PIC 9(06).
    03  WS-END-TIME-R REDEFINES WS-END-TIME.
        05  WS-END-TIME-H    PIC 9(02).
        05  WS-END-TIME-M    PIC 9(02).
        05  WS-END-TIME-S    PIC 9(02).
    03  WS-DURATION-TIME.
        05  WS-DUR-TIME-H    PIC 9(02).  *> OR PIC Z9.
        05  FILLER           PIC X VALUE ":".
        05  WS-DUR-TIME-M    PIC 9(02).
        05  FILLER           PIC X VALUE ":".
        05  WS-DUR-TIME-S    PIC 9(02).
    03  START-SECONDS        PIC 9(06).
    03  END-SECONDS          PIC 9(06).
    03  NUMBER-OF-SECONDS    PIC 9(06).

     ...
        ACCEPT WS-START-TIME FROM TIME.
     ...
        ACCEPT WS-END-TIME FROM TIME.
        COMPUTE START-SECONDS =
           ( WS-START-TIME-H * 3600 ) +
           ( WS-START-TIME-M *   60 ) +
           ( WS-START-TIME-S        ).
        COMPUTE END-SECONDS =
           ( WS-END-TIME-H * 3600 ) +
           ( WS-END-TIME-M *   60 ) +
           ( WS-END-TIME-S        ).
        COMPUTE NUMBER-OF-SECONDS = END-SECONDS - START-SECONDS.
        DIVIDE NUMBER-OF-SECONDS BY 3600 GIVING WS-DUR-TIME-H REMAINDER NUMBER-OF-SECONDS.
        DIVIDE NUMBER-OF-SECONDS BY 60 GIVING WS-DUR-TIME-M REMAINDER WS-DUR-TIME-S.

        DISPLAY "Total running time : " WS-DURATION-TIME.
Marcel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top