Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
comparing 2 dates for 10 years

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: comparing 2 dates for 10 years
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    Post subject: Re: comparing 2 dates for 10 years
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    Post subject:
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    Post subject: Re: comparing 2 dates for 10 years
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Tue Apr 18, 2006 3:54 pm    Post subject: Re: comparing 2 dates for 10 years
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    Post subject: Re: comparing 2 dates for 10 years
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    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 Comparing 2 Files using Current time arunsoods SYNCSORT 9 Fri Sep 22, 2017 6:00 pm
No new posts Allianz Technology - Mainframe 3+ Yea... sooraj184 Mainframe Jobs 0 Mon Jul 31, 2017 2:17 pm
No new posts CA-Endevor Admin - 3 years minimum vasanthz Mainframe Jobs 0 Tue Apr 04, 2017 5:36 am
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
No new posts Mainframe Openings for 3 to 5 years i... muralikrishnan_new Mainframe Jobs 0 Fri Jun 17, 2016 4:48 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us