Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to calculate the time difference?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Geo

New User


Joined: 25 May 2006
Posts: 1

PostPosted: Thu May 25, 2006 10:00 am    Post subject: How to calculate the time difference?
Reply with quote

Hi,

How to calculate the difference between 2 given times.

Eg.

Input:
HHMMSSXX
04:45:12:45
04:42:54:23

How to write a program to calculate the difference between 2 given time like the above mentioned?
Is there any built-in function?
It's quite emergency.Someone plz give me a reply as early as possible.
Back to top
View user's profile Send private message

gskulkarni

New User


Joined: 01 Mar 2006
Posts: 70

PostPosted: Thu May 25, 2006 11:09 am    Post subject:
Reply with quote

This is a tricky one. The date difference can be calculated using COBOL functions. I have stated an example below.
The following example shows how to calculate a due date that is 90
days from today. The first eight characters returned by the CURRENT-DATE function
represent the date in a 4-digit year, 2-digit month, and 2-digit day format
(YYYYMMDD). In the example, this date is converted to its integer value. Then 90
is added to this value, and the integer is converted back to the YYYYMMDD format.
Code:

01 Date-1-YYYYMMDD Pic 9(8).
01 Date-2-YYYYMMDD Pic 9(8).
01 Integer-Form Pic S9(9).
...
Move Function Current-Date(1:8) to Date-1-YYYYMMDD
Compute Integer-Form-Date-1 = Function Integer-of-Date(Date-1-YYYYMMDD)
Compute Integer-Form-Date-2 = Function Integer-of-Date(Date-2-YYYYMMDD)
Compute day-diff-dates = Integer-Form-Date-2 - Integer-Form-Date-1

This gives difference of days between dates.
However, time difference will have to be calculated with program logic (I think!)

parse your time HH:MM:SS:NN as
Code:
01 WS-TIME.
      05 WS-HR PIC 9(02)
      05 FILLER PIC X(01) VALUE ':'
      05 WS-MM PIC 9(02)
      05 FILLER PIC X(01) VALUE ':'
      05 WS-SS PIC 9(02)
      05 FILLER PIC X(01) VALUE ':'
      05 WS-NN PIC 9(02)

MOVE INPUT-TIME TO WS-TIME.
MOVE INPUT-OTHER-TIME TO WS-TIME-2 (defined in similar fashion as WS-TIME).


Now calculated HH, MM, SS and NN difference separately. and club output in WS-TIME-RESULT which should be defined in similar fashion as WS-TIME. Fillers would be ':'.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed May 31, 2006 3:43 am    Post subject: Re: How to calculate the time difference?
Reply with quote

Geo,

Try this code for the difference in time. If the start time is greater than the end time, the code assumes passage of one day.

Code:

 01  START-HHMMSSDD.                         
    05  START-HH                PIC 9(2).   
    05  FILLER                  PIC X.       
    05  START-MM                PIC 9(2).   
    05  FILLER                  PIC X.       
    05  START-SS                PIC 9(2).   
    05  FILLER                  PIC X.       
    05  START-DD                PIC 9(2).   
 01  END-HHMMSSDD.                           
    05  END-HH                  PIC 9(2).   
    05  FILLER                  PIC X.     
    05  END-MM                  PIC 9(2).   
    05  FILLER                  PIC X.     
    05  END-SS                  PIC 9(2).   
    05  FILLER                  PIC X.     
    05  END-DD                  PIC 9(2).   
                                                           
 01  NO-DAYS                     PIC 9(3).                 
                                                           
 01  START-TIME                  PIC 9(11).               
 01  END-TIME                    PIC 9(11).               
 01  DIFF-TIME                   PIC 9(11).               
                                                           
 01  DIFF-HHMMSSDD.                                       
    05  DIFF-HH                 PIC 99.                   
    05  FILLER                  PIC X       VALUE ':'.   
    05  DIFF-MM                 PIC 99.                   
    05  FILLER                  PIC X       VALUE ':'.   
    05  DIFF-SS                 PIC 99.                   
    05  FILLER                  PIC X       VALUE '.'.   
    05  DIFF-DD                 PIC 99. 
               
 PROCEDURE DIVISION.                                             
                                                                 
    MOVE '04:45:12.45'          TO START-HHMMSSDD.           
    MOVE '04:42:54.23'          TO END-HHMMSSDD.             
                                                                 
    IF END-HHMMSSDD < START-HHMMSSDD                             
    THEN                                                         
        MOVE 1                  TO NO-DAYS                       
    ELSE                                                         
        MOVE 0                  TO NO-DAYS                       
    END-IF.                                                     
                                                                 
    MOVE 0                      TO START-TIME                   
                                    END-TIME.                     
                                                   
    COMPUTE START-TIME = START-HH * 60         
    COMPUTE START-TIME = (START-TIME           
                          + START-MM) * 60     
    COMPUTE START-TIME = (START-TIME           
                          + START-SS) * 100     
    COMPUTE START-TIME = (START-TIME           
                          + START-DD)           
                                                 
    COMPUTE END-TIME = NO-DAYS * 24             
    COMPUTE END-TIME = (END-TIME               
                          + END-HH) * 60       
    COMPUTE END-TIME = (END-TIME               
                          + END-MM) * 60       
    COMPUTE END-TIME = (END-TIME               
                          + END-SS) * 100       
    COMPUTE END-TIME = (END-TIME               
                           + END-DD                                                                         
                                                             
    COMPUTE DIFF-TIME = END-TIME - START-TIME.               
                                                             
    DIVIDE DIFF-TIME BY 100     GIVING DIFF-TIME             
                                REMAINDER DIFF-DD.           
    DIVIDE DIFF-TIME BY 60      GIVING DIFF-TIME             
                                REMAINDER DIFF-SS.           
    DIVIDE DIFF-TIME BY 60      GIVING DIFF-TIME             
                                REMAINDER DIFF-MM.           
    MOVE DIFF-TIME              TO DIFF-HH.                 
                                                             
    DISPLAY 'START-HHMMSSDD : ' START-HHMMSSDD.             
    DISPLAY 'END-HHMMSSDD   : ' END-HHMMSSDD.               
    DISPLAY 'DIFF-HHMMSSDD  : ' DIFF-HHMMSSDD.               
                                                             
    GOBACK.                                                 


With START-HHMMSSDD = '04:45:12.45' and END-HHMMSSDD = '04:42:54.23', result is:

Code:

.START-HHMMSSDD : 04:45:12.45
.END-HHMMSSDD   : 04:42:54.23
.DIFF-HHMMSSDD  : 23:57:41.78


With START-HHMMSSDD = '04:42:54.23' and END-HHMMSSDD = '04:45:12.45', result is:

Code:

.START-HHMMSSDD : 04425423   
.END-HHMMSSDD   : 04451245   
.DIFF-HHMMSSDD  : 00:26:22.00


If you have problems wit the code, let me know.

Dave
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed May 31, 2006 3:46 am    Post subject: Re: How to calculate the time difference?
Reply with quote

OOPs,

With START-HHMMSSDD = '04:42:54.23' and END-HHMMSSDD = '04:45:12.45', result is:


Code:

.START-HHMMSSDD : 04:42:54.23
.END-HHMMSSDD   : 04:45:12.45
.DIFF-HHMMSSDD  : 00:02:18.22
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. 00D3003B - time outs in DB2 when invo... chavinash2004 DB2 2 Mon Oct 09, 2017 4:39 pm
No new posts VSAM RLS Wait time blayek JCL & VSAM 2 Mon Oct 02, 2017 9:05 pm
No new posts Comparing 2 Files using Current time arunsoods SYNCSORT 9 Fri Sep 22, 2017 6:00 pm
No new posts Difference in SORT & ICETOOL Mohan Kothakota DFSORT/ICETOOL 5 Fri Sep 22, 2017 4:56 pm
No new posts Regarding time parameter shanthi gude JCL & VSAM 7 Mon Sep 04, 2017 2:31 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us