Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
mani_jnumca

New User

Joined: 18 Jan 2006
Posts: 16
Location: PUNE

 Posted: Thu Mar 09, 2006 9:24 am    Post subject: Cobol logic for Calculating difference between dates 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

priyesh.agrawal

Senior Member

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

 Posted: Thu Mar 09, 2006 7:58 pm    Post subject: Re: cobol logic for calculating difference between dates What is Input & how do you like to see output... Regards, Priyesh.
martin9

Active User

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

 Posted: Thu Mar 09, 2006 8:11 pm    Post subject: 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
DavidatK

Active Member

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

Posted: Fri Mar 10, 2006 1:55 am    Post subject: Re: cobol logic for calculating difference between dates

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
mani_jnumca

New User

Joined: 18 Jan 2006
Posts: 16
Location: PUNE

 Posted: Fri Mar 10, 2006 11:41 am    Post subject: 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
Vidusha

New User

Joined: 01 Feb 2006
Posts: 20
Location: Chennai

 Posted: Fri Mar 10, 2006 3:13 pm    Post subject: 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
mani_jnumca

New User

Joined: 18 Jan 2006
Posts: 16
Location: PUNE

 Posted: Fri Mar 10, 2006 3:31 pm    Post subject: thnks vidusha i have checked it its look fine
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics How to display offset thru cobol prog... tvinodkumar7 CICS 0 Sun Apr 22, 2018 8:42 pm Linkage editor is part of COBOL, z/OS... ankit.jain COBOL Programming 4 Fri Apr 20, 2018 4:17 pm Difference between EQUAL and EQUAL TO... jithinraghavan COBOL Programming 3 Thu Apr 19, 2018 2:22 am Call COBOL or PLI with a click from w... vaibhav gs All Other Mainframe Topics 1 Mon Apr 16, 2018 7:29 pm COBOL MVS options BiswajitDG COBOL Programming 8 Fri Apr 06, 2018 12:35 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us