View previous topic :: View next topic
|
Author |
Message |
chander123
New User
Joined: 12 Apr 2006 Posts: 2
|
|
|
|
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 |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
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 |
|
|
martin9
Active User
Joined: 01 Mar 2006 Posts: 290 Location: Basel, Switzerland
|
|
|
|
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 |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
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 |
|
|
chander123
New User
Joined: 12 Apr 2006 Posts: 2
|
|
|
|
Hi Dave and Martin
I want to compare two dates for greater than or equal to 10 years difference |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
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 |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
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 |
|
|
|