IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

comparing 2 dates for 10 years


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
chander123

New User


Joined: 12 Apr 2006
Posts: 2

PostPosted: Wed Apr 12, 2006 12:45 pm
Reply with quote

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...
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 Apr 12, 2006 7:04 pm
Reply with quote

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
Back to top
View user's profile Send private message
martin9

Active User


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

PostPosted: Wed Apr 12, 2006 7:16 pm
Reply with quote

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
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 Apr 12, 2006 7:28 pm
Reply with quote

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
Back to top
View user's profile Send private message
chander123

New User


Joined: 12 Apr 2006
Posts: 2

PostPosted: Tue Apr 18, 2006 11:08 am
Reply with quote

Hi Dave and Martin
I want to compare two dates for greater than or equal to 10 years difference
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


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

PostPosted: Tue Apr 18, 2006 3:54 pm
Reply with quote

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.
Back to top
View user's profile Send private message
DavidatK

Active Member


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

PostPosted: Tue Apr 18, 2006 7:08 pm
Reply with quote

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
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Need to fetch data from so many DB2 t... DB2 9
No new posts Amount of days between two dates PL/I & Assembler 8
No new posts Comparing Header and Trailer. DFSORT/ICETOOL 7
No new posts Mainframe developers 3 - 6 years exp Mainframe Jobs 0
No new posts Mainframe - PL1, JCL, DB2 opening - 5... Mainframe Jobs 0
Search our Forums:

Back to Top