Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 
Finding difference between two dates to convert to hours

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

New User


Joined: 02 Nov 2006
Posts: 17

PostPosted: Thu Nov 02, 2006 11:24 pm    Post subject: Finding difference between two dates to convert to hours
Reply with quote

hi everyone,

I want to calculate the difference between two dates in Cobol and convert it into hours.
below code is not giving me the correct result.

Code:
WS-INT-DATE1 PIC 9(8) VALUE 20030924.
WS-INT-DATE2 PIC 9(8) VALUE 20020924.
WS-NEW-DATE PIC S9(9) COMP

move ws-table-date to ws-int-date1
move ws-table-date to ws-int-date2


COMPUTE WS-NEW-DATE =
FUNCTION INTEGER-OF-DATE(WS-INT-DATE1) -
FUNCTION INTEGER-OF-DATE(WS-INT-DATE2)

COMPUTE WS-DATE =
FUNCTION DATE-OF-INTEGER(WS-NEW-DATE)

COMPUTE WS-HOURS = WS-DATE * 24

DISPLAY WS-DATE


waiting for the reply.
Back to top
View user's profile Send private message

David P

Active User


Joined: 11 Apr 2005
Posts: 106
Location: Cincinnati Ohio

PostPosted: Thu Nov 02, 2006 11:57 pm    Post subject: Re: date difference cobol
Reply with quote

Hi,

As per your code
move ws-table-date to ws-int-date1
move ws-table-date to ws-int-date2

You are moving the same value in different fields before calculating their difference. (ws-table-date)

I believe you will always get zero as result....

Please confirm this once.

-thanks
David P.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Nov 03, 2006 12:09 am    Post subject: Re: Finding difference between two dates to convert to hours
Reply with quote

Adarsh,

The actual problem is in this piece of the code you are using.
Code:
COMPUTE WS-DATE =
FUNCTION DATE-OF-INTEGER(WS-NEW-DATE)

COMPUTE WS-HOURS = WS-DATE * 24

You dont need to convert it back to DATE in order to multiply it with 24. Just take a difference and multiply by 24.
Check the code below and let me know, if problems.
Code:
WS-INT-DATE1 PIC 9(8) VALUE 20030924.
WS-INT-DATE2 PIC 9(8) VALUE 20020924.
WS-NEW-DATE  PIC S9(9) COMP
WS-HOURS     PIC 99999999.

*move ws-table-date to ws-int-date1       /* These are not necessary for testing as u already initialized values.
*move ws-table-date to ws-int-date2    /* These are not necessary for testing as u already initialized values.
COMPUTE TEMP-1 = FUNCTION INTEGER-OF-DATE(WS-INT-DATE1).
COMPUTE TEMP-2 = FUNCTION INTEGER-OF-DATE(WS-INT-DATE2).
COMPUT WS-NEW-DATE = TEMP1 - TEMP2.
COMPUTE WS-HOURS = WS-NEW-DATE * 24.
DISPLAY "FIRST DATE: " WS-INT-DATE1.
DISPLAY "SECOND DATE: " WS-INT-DATE2.
DISPLAY "DIFFERENCE-DAY: " WS-NEW-DATE.
DISPLAY "WS-HOURS :" WS-HOURS.
Back to top
View user's profile Send private message
adarsh444

New User


Joined: 02 Nov 2006
Posts: 17

PostPosted: Fri Nov 03, 2006 12:39 am    Post subject:
Reply with quote

THANKS A LOT
Back to top
View user's profile Send private message
adarsh444

New User


Joined: 02 Nov 2006
Posts: 17

PostPosted: Fri Nov 03, 2006 1:52 am    Post subject:
Reply with quote

I got the result its working fine.
If i want to calculate the difference between time in Cobol.
I cannot use FUNCTION DATE-OF-INTEGER(WS-INT-TIME).
Please suggest the efficient way to calculate the difference.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Nov 03, 2006 2:11 am    Post subject: Re: Finding difference between two dates to convert to hours
Reply with quote

Quote:
If i want to calculate the difference between time in Cobol.
I cannot use FUNCTION DATE-OF-INTEGER(WS-INT-TIME).

First you'll have to understand the functioning of these COBOL Functions.

INTEGER-OF-DATE: returned value is an integer that is the number of days that the date represented by input date succeeds December 31, 1600 in the Gregorian calendar. The function result is a seven-digit integer with a range from 1 to 3,067,671.

DATE-OF-INTEGER: reversal of the function INTEGER-OF-DATE. The function result is an eight-digit integer. The returned value is an integer of the form YYYYMMDD.
Quote:
Please suggest the efficient way to calculate the difference.
Now if you want to calcualte time-difference, you may probably want to show some input format in which your time string comes. May be we can figure out something.
Back to top
View user's profile Send private message
adarsh444

New User


Joined: 02 Nov 2006
Posts: 17

PostPosted: Fri Nov 03, 2006 2:22 am    Post subject:
Reply with quote

I have

TIME1 VALUE HH.MM.SS.
TIME2 VALUE HH.MM.SS.

I want to calculate the time difference and
retrieve the hours.


COMPUTE WS-TIME-DIFF = TIME1 - TIME2

Does WS-TIME-DIFF(1:2) give the exact time difference in hours.

Could you suggest the efficient way to do this either using cobol or
sql- query?

Waiting for ur reply
Back to top
View user's profile Send private message
adarsh444

New User


Joined: 02 Nov 2006
Posts: 17

PostPosted: Fri Nov 03, 2006 2:42 am    Post subject:
Reply with quote

Just a correction.It's to be done using cobol functions and TIME1, TIME2
are not the table fields.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Mon Nov 06, 2006 2:50 am    Post subject: Re: Finding difference between two dates to convert to hours
Reply with quote

You could have better shown an input example with espected output.
Does time variable contain a 24 hr clock?
Quote:
Does WS-TIME-DIFF(1:2) give the exact time difference in hours.

Not necessarily... it depends what you expect from the output...
If Time-1 = 11:59:59 & Time-2 = 10:00:00... This difference would give you 1 hr. difference, but you might have been looking for a 2 instead.

So probably Evaluate/IFs can be used to round off the timestamp.
Back to top
View user's profile Send private message
DavidatK

Active Member


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

PostPosted: Mon Nov 06, 2006 10:25 pm    Post subject: Re: Finding difference between two dates to convert to hours
Reply with quote

adarsh444,

Code:

01  FROM-TIME.                                   
    05  HH                      PIC 99.           
    05  FILLER                  PIC X.           
    05  MM                      PIC 99.           
    05  FILLER                  PIC X.           
    05  SS                      PIC 99.           
01  TO-TIME.                                     
    05  HH                      PIC 99.           
    05  FILLER                  PIC X.           
    05  MM                      PIC 99.           
    05  FILLER                  PIC X.           
    05  SS                      PIC 99.           
01  DAYS-DIFF                   PIC S9(3).       
01  HOUR-DIFF                   PIC S9(5)V9(4).   
01  DISPLAY-HOUR-DIFF           PIC -----9.9999. 
01  DISPLAY-DAYS-DIFF           PIC +++9.         

    MOVE +1                     TO DAYS-DIFF.
    MOVE '16:42:16'             TO FROM-TIME.             
    MOVE '22:10:30'             TO TO-TIME.               
                                                                       
    COMPUTE HOUR-DIFF                                     
        = ((DAYS-DIFF * 86400)                             
        +  (HH OF TO-TIME * 3600)                         
        +  (MM OF TO-TIME * 60)                           
        +   SS OF TO-TIME                                 
        -  (HH OF FROM-TIME * 3600)                       
        -  (MM OF FROM-TIME * 60)                         
        -   SS OF FROM-TIME)                               
        / 3600.                                           
                                                           
    MOVE HOUR-DIFF              TO DISPLAY-HOUR-DIFF.     
    MOVE DAYS-DIFF              TO DISPLAY-DAYS-DIFF.     
    DISPLAY 'THE NUMBER OF HOURS BETWEEN ' FROM-TIME       
            ' AND ' TO-TIME ' ' DISPLAY-DAYS-DIFF ' DAYS' 
            ' IS ' DISPLAY-HOUR-DIFF.     


Results:

Code:

.SARPAGE 4                                                                 
.                                                                           
.THE NUMBER OF HOURS BETWEEN 16:42:16 AND 22:10:30   +1 DAYS IS     29.4705


Round the result as you please.

Dave
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
No new posts Finding IMS resource blocker after se... Hooman24 IMS DB/DC 1 Wed Aug 16, 2017 9:17 pm
No new posts Convert CLIST to REXX cvnlynn CLIST & REXX 12 Tue Jun 27, 2017 2:06 am
No new posts finding delayed job/s in OPC jzhardy IBM Tools 0 Mon May 29, 2017 9:04 am
No new posts Convert current to hex value gopurs DFSORT/ICETOOL 4 Wed Feb 15, 2017 5:40 am
No new posts Difference between TWALENG and TWASIZE Arunkumar Chandrasekaran CICS 3 Tue Jan 03, 2017 12:57 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us