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
 

 

Cobol logic for Calculating difference between dates

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

New User


Joined: 18 Jan 2006
Posts: 16
Location: PUNE

PostPosted: Thu Mar 09, 2006 9:24 am    Post subject: Cobol logic for Calculating difference between dates
Reply with quote

hi every body

can any body help me for calculating the difference between two dates in the form of year month and date


thanks
mani
Back to top
View user's profile Send private message

priyesh.agrawal

Senior Member


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

PostPosted: Thu Mar 09, 2006 7:58 pm    Post subject: Re: cobol logic for calculating difference between dates
Reply with quote

What is Input & how do you like to see output...

Regards,
Priyesh.
Back to top
View user's profile Send private message
martin9

Active User


Joined: 01 Mar 2006
Posts: 288
Location: Basel, Switzerland

PostPosted: Thu Mar 09, 2006 8:11 pm    Post subject:
Reply with quote

difference in what?
1. in days
2. in months
3. in years
possibly you need this in days,
then you must calculate your dates
into whole numbers first, ok.

unfortunately the date format is quite a bit wired...
just think of changing the number of days all 4 years
and not on all 400 years! (gregorian rule).

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

Active Member


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

PostPosted: Fri Mar 10, 2006 1:55 am    Post subject: Re: cobol logic for calculating difference between dates
Reply with quote

mani,

This routine will give you the number of days between two dates.

Code:

WORKING-STORAGE SECTION.                                       
                                                               
01  PROGRAM-VARIABLES.                                         
    05  WS-DATE-Y-M-D-1          PIC X(10).                     
    05  WS-DATE-Y-M-D-2          PIC X(10).                     
    05  WS-DATE-Y-M-D            PIC X(10).                     
    05  WS-DATE-YMD              PIC 9(8).                     
    05  WS-DAYS-TO-DATE          PIC 9(9).                     
    05  WS-DAYS-TO-DATE-1        PIC 9(9).                     
    05  WS-DAYS-TO-DATE-2        PIC 9(9).                     
    05  WS-DAY-IN-WEEK-NBR       PIC 9.                         
    05  WS-DAY-IN-WEEK-NBR-1     PIC 9.                         
    05  WS-DAY-IN-WEEK-NBR-2     PIC 9.                         
    05  WS-DAYS-DIFF             PIC -(5)9.                     
    05  WS-DAYS.                                               
      10  FILLER                 PIC X(36)   VALUE             
      'SUNDAY   MONDAY   TUESDAY  WEDNESDAY'.                   
      10  FILLER                 PIC X(27)   VALUE             
      'THURSDAY FRIDAY   SATURDAY '.                           
PROCEDURE DIVISION.                                                 
                                                                   
    MOVE '2006-01-01'           TO WS-DATE-Y-M-D-1.                 
    MOVE '2006-03-01'           TO WS-DATE-Y-M-D-2.                 
                                                                   
    MOVE WS-DATE-Y-M-D-1        TO WS-DATE-Y-M-D.                   
    PERFORM P2000-COMPUTE-DAYS-TO-DATE.                             
    MOVE WS-DAYS-TO-DATE        TO WS-DAYS-TO-DATE-1.               
    MOVE WS-DAY-IN-WEEK-NBR     TO WS-DAY-IN-WEEK-NBR-1.           
                                                                   
    MOVE WS-DATE-Y-M-D-2        TO WS-DATE-Y-M-D.                   
    PERFORM P2000-COMPUTE-DAYS-TO-DATE.                             
    MOVE WS-DAYS-TO-DATE        TO WS-DAYS-TO-DATE-2.               
    MOVE WS-DAY-IN-WEEK-NBR     TO WS-DAY-IN-WEEK-NBR-2.           
                                                                   
    COMPUTE WS-DAYS-DIFF = WS-DAYS-TO-DATE-2 - WS-DAYS-TO-DATE-1.   
                                                                   
    DISPLAY ' THERE ARE ' WS-DAYS-DIFF                             
            ' DAYS BETWEEN ' DAY-IN-WEEK (WS-DAY-IN-WEEK-NBR-1)     
            ' ' WS-DATE-Y-M-D-1                                     
            ' AND ' DAY-IN-WEEK (WS-DAY-IN-WEEK-NBR-2)           
            ' ' WS-DATE-Y-M-D-2.                                 
                                                                 
    GOBACK.                                                       
                                                                 
P2000-COMPUTE-DAYS-TO-DATE.                                       
    MOVE WS-DATE-Y-M-D(1:4)   TO WS-DATE-YMD(1:4).               
    MOVE WS-DATE-Y-M-D(6:2)   TO WS-DATE-YMD(5:2).               
    MOVE WS-DATE-Y-M-D(9:2)   TO WS-DATE-YMD(7:2).               
    COMPUTE WS-DAYS-TO-DATE                                       
            = FUNCTION INTEGER-OF-DATE (WS-DATE-YMD).             
    COMPUTE WS-DAY-IN-WEEK-NBR                                   
            = WS-DAYS-TO-DATE                                     
            - FUNCTION INTEGER (WS-DAYS-TO-DATE / 7) * 7 + 1.     

Code:

.SARPAGE 41                                                                   
.                                                                             
. THERE ARE     59 DAYS BETWEEN SUNDAY    2006-01-01 AND WEDNESDAY 2006-03-01


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

New User


Joined: 18 Jan 2006
Posts: 16
Location: PUNE

PostPosted: Fri Mar 10, 2006 11:41 am    Post subject:
Reply with quote

i need difference between dates in the form of
yy/mm/dd format
if
i have input
date1----2006/01/01
date2----1956/02/22


then what is the difference between thease two dates in the form of
diffyy/diffmm/diffdd


thanks
mani
Back to top
View user's profile Send private message
Vidusha

New User


Joined: 01 Feb 2006
Posts: 20
Location: Chennai

PostPosted: Fri Mar 10, 2006 3:13 pm    Post subject:
Reply with quote

Hi Mani,

Here is a logic for doing that.

101 WS-DATE1 PIC X(10)
01 REDEFINES WS-DATE1
02 WS-DATE1-YYYY PIC 9(4)
02 FILLER PIC X(1)
02 WS-DATE1-MM PIC 9(2)
02 FILLER PIC X(1)
02 WS-DATE1-DD PIC 9(2)
*
01 WS-DATE2 PIC X(10)
01 REDEFINES WS-DATE2
02 WS-DATE2-YYYY PIC 9(4)
02 FILLER PIC X(1)
02 WS-DATE2-MM PIC 9(2)
02 FILLER PIC X(1)
02 WS-DATE2-DD PIC 9(2)

01 WS-DIFF PIC X(10)
01 REDEFINES WS-DIFF
02 WS-YYYY PIC 9(4)
02 FILLER PIC X(1)
02 WS-MM PIC 9(2)
02 FILLER PIC X(1)
02 WS-DD PIC 9(2)
*
SUBTRACT WS-DATE2-YYYY FROM WS-DATE1-YYYY GIVING WS-YYYY
IF WS-DATE1-MM < WS-DATE2-MM
SUBTRACT 1 FROM WS-YYYY
COMPUTE WS-MM = WS-DATE1-MM + 12 - WS-DATE2-MM
ELSE
SUBTRACT WS-DATE2-MM FROM WS-DATE1-MM GIVING WS-MM
END-IF
IF WS-DATE1-DD < WS-DATE2-DD
IF WS-DATE2-MM = 02
COMPUTE WS-DD = WS-DATE1-DD + 28 - WS-DATE2-DD
ELSE
IF WS-DATE2-MM = 01 OR 03 OR 05 OR 07 OR 08 OR 10 OR 12
COMPUTE WS-DD = WS-DATE1-DD + 31 - WS-DATE2-DD
ELSE
COMPUTE WS-DD = WS-DATE1-DD + 30 - WS-DATE2-DD
END-IF
END-IF
SUBTRACT 1 FROM WS-MM
ELSE
SUBTRACT WS-DATE2-DD FROM WS-DATE1-DD GIVING WS-DD
END-IF

(need to take care of Leap year as well)
If anything wrong, please correct and let me know

Thanks
Vidusha
Back to top
View user's profile Send private message
mani_jnumca

New User


Joined: 18 Jan 2006
Posts: 16
Location: PUNE

PostPosted: Fri Mar 10, 2006 3:31 pm    Post subject:
Reply with quote

thnks vidusha
i have checked it
its look fine
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. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts COBOL Code Parsers and Lineage Establ... balimanja COBOL Programming 2 Tue May 02, 2017 3:30 am
No new posts Cobol upgrade - source code missing f... gthmrj IBM Tools 1 Wed Apr 26, 2017 6:04 pm
No new posts COBOL Programming Sandpit? jodrisco COBOL Programming 6 Wed Apr 12, 2017 3:47 am


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