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

Author Message
chander123

New User

Joined: 12 Apr 2006
Posts: 2

 Posted: Wed Apr 12, 2006 12:45 pm    Post subject: comparing 2 dates for 10 years How to compare 2 dates (yyyy mm dd) . I want to know difference in term of years(my requirement is 10 years) between them.. My idea Compare years .. if it is more than 10 it is satisfied if it is equal 10 the check for months if months are equal then check for dates Let me Know if any COBOL funtion available or easy method...

DavidatK

Active Member

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

 Posted: Wed Apr 12, 2006 7:04 pm    Post subject: Re: comparing 2 dates for 10 years I'm sorry, I don't understand exactly what you want. Do you want to know the difference in YYYYMMDD between two dates i.e. 20060504- 20030301 = 00020203 (2 years, 2 months, 3 days) or do you want to compare two dates for exactly 10 years difference or do you want to campare two dates for less than 10 years difference or ? Please come back, Dave
martin9

Active User

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

 Posted: Wed Apr 12, 2006 7:16 pm    Post subject: hy guys, it is really not clear, what chander123 really want as result... but with the subtraction above you cannot solve it. the date format is a s... format (sry), therefore you have to calculate it. 20060504- 20030301 = 00020203 (2 years, 2 months, 3 days) this is not wrong but look below 20060301-20030504 = 29797 (2 years, 97 months, 97 days)??? no not really... maybe you can solve this with intrinsic functions also, i never tried... i would quickly write that logic, which is not that complicated, or might be that you have a 'clever' date subroutine at yout site... martin9
DavidatK

Active Member

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

 Posted: Wed Apr 12, 2006 7:28 pm    Post subject: Re: comparing 2 dates for 10 years The example of i.e. 20060504- 20030301 = 00020203 (2 years, 2 months, 3 days) was meant to be a logical subtraction, just to understand what chander123 wanted as a result. We all, I hope, understand that a arithmetic subtraction of dates does not work. Dave
chander123

New User

Joined: 12 Apr 2006
Posts: 2

 Posted: Tue Apr 18, 2006 11:08 am    Post subject: Hi Dave and Martin I want to compare two dates for greater than or equal to 10 years difference
priyesh.agrawal

Senior Member

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

Posted: Tue Apr 18, 2006 3:54 pm    Post subject: Re: comparing 2 dates for 10 years

chander,

Here is a simple code with IF-THEN LOGIC to check if there is a gape of mor ethan 10 yrs between 2 dates or not. But you need to make your requirements more clear, in order to get exact what u r looking for.

another way can be converting it to JULIAN Format & then compare.
 Code: 01 WS1-DATE.       05 WS1-YEAR   X(04).    05 WS1-FILLER   X(01).    05 WS1-MONTH   X(02).    05 WS1-FILLER   X(01).    05 WS1-DAY   X(02). 01 WS2-DATE.       05 WS2-YEAR   X(04).    05 WS2-FILLER   X(01).    05 WS2-MONTH   X(02).    05 WS2-FILLER   X(01).    05 WS2-DAY   X(02). IF (WS2-YEAR - WS1-YEAR) > 10    DISPLAY 'CONDITION SATISFIED- MORE THAN 10 YRS GAPE' ELSE    IF (WS2-YEAR - WS1-YEAR) < 10       DISPLAY 'LESS THAN 10 YRS DIFFERENCE'    ELSE       PERFORM 'EQUAL-TO-TEN'    END-IF END-IF. EQUAL-TO-TEN. IF WS2-MONTH > WS1-MONTH    DISPLAY 'CONDITION SATISFIED- MORE THAN 10 YRS GAPE' ELSE    IF WS2-MONTH < WS1-MONTH       DISPLAY 'LESS THAN 10 YRS DIFFERENCE'    ELSE       PERFORM 'EQUAL-TO-TEN-MONTH'    END-IF END-IF. EQUAL-TO-TEN-MONTHS. IF WS2-DAY > WS1-DAY    DISPLAY 'CONDITION SATISFIED- MORE THAN 10 YRS GAPE' ELSE    IF WS2-DAY < WS1-DAY       DISPLAY 'LESS THAN 10 YRS DIFFERENCE'    ELSE       DISPLAY 'I CANT CHECK FOR HOURS AND MINUTE NOW'    END-IF END-IF.

Regards,
Priyesh.
DavidatK

Active Member

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

Posted: Tue Apr 18, 2006 7:08 pm    Post subject: Re: comparing 2 dates for 10 years

chander123,

 Quote: I want to compare two dates for greater than or equal to 10 years difference

This is exceptionally easy if you only want to know if the dates are GE 10 years, and not how much different.

 Code: WORKING-STORAGE SECTION.                                                                                                               01  START-DATE-YYYYMMDD         PIC 9(8)     VALUE 19991023.       01  WORK-DATE-YYYYMMDD          PIC 9(8).                           01  END-DATE-YYYYMMDD           PIC 9(8)     VALUE 20091024.                                                                           LINKAGE SECTION.                                                   PROCEDURE DIVISION.                                                                                                                    *--- add 10 years to start date           ADD 100000                  TO START-DATE-YYYYMMDD                                         GIVING WORK-DATE-YYYYMMDD.                  IF END-DATE-YYYYMMDD >= WORK-DATE-YYYYMMDD                         THEN                                                                   DISPLAY END-DATE-YYYYMMDD                                                   ' IS GREATER OR EQUAL TO 10 YEARS FROM '                           START-DATE-YYYYMMDD                                     ELSE                                                                   DISPLAY END-DATE-YYYYMMDD ' IS LESS THAN 10 YEARS FROM '                   START-DATE-YYYYMMDD                                     END-IF.                                                             GOBACK.

Results of test

 Code: 20091022 IS LESS THAN 10 YEARS FROM 19991023  20091023 IS GREATER OR EQUAL TO 10 YEARS FROM 19991023  20091024 IS GREATER OR EQUAL TO 10 YEARS FROM 19991023

Dave
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics To get Non matching row after compari... vinu78 DB2 7 Fri Jan 05, 2018 5:43 pm Comparing dates in different formats migusd SYNCSORT 4 Sat Nov 18, 2017 3:02 am Comparing current time with the time ... arunsoods SYNCSORT 1 Mon Oct 30, 2017 4:07 pm Comparing 2 Files using Current time arunsoods SYNCSORT 9 Fri Sep 22, 2017 6:00 pm Allianz Technology - Mainframe 3+ Yea... sooraj184 Mainframe Jobs 0 Mon Jul 31, 2017 2:17 pm

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