View previous topic :: View next topic
|
Author |
Message |
vin12pr Warnings : 1 New User
Joined: 14 Jun 2006 Posts: 56
|
|
|
|
Can you please help me in finding the number of years from two dates which are in the format dd.mm.yyyy. i.e. , no of years between two dates. |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi there,
I think you can use DATEDF function for this.
DATEDF ? Calculate Date Difference
This program calculates the number of days, weeks, and months between the two given dates. The one argument is the following array. BEGIN-DATE and END-DATE must be specified by the calling program. The remaining fields are calculated by this routine. The four RESULT fields are the count for each. BEGIN-WEEK-DAY and END-WEEK-DAY are 1 = Sunday through 7 = Saturday.
01 DATE-CALCULATION.
03 BEGIN-DATE.
05 BD-CENT PIC S99 USAGE COMP-5.
05 BD-YEAR PIC S99 USAGE COMP-5.
05 BD-MNTH PIC S99 USAGE COMP-5.
05 BD-DAY PIC S99 USAGE COMP-5.
03 END-DATE.
05 ED-CENT PIC S99 USAGE COMP-5.
05 ED-YEAR PIC S99 USAGE COMP-5.
05 ED-MNTH PIC S99 USAGE COMP-5.
05 ED-DAY PIC S99 USAGE COMP-5.
03 RESULT-DAYS PIC S9999 USAGE COMP-5.
03 RESULT-WEEKS PIC S9999 USAGE COMP-5 OCCURS 7 TIMES.
03 RESULT-MONTHS PIC S9999 USAGE COMP-5.
03 RESULT-YEARS PIC S9999 USAGE COMP-5.
03 BEGIN-WEEK-DAY PIC S9999 USAGE COMP-5.
03 END-WEEK-DAY PIC S9999 USAGE COMP-5.
Hope it will helpful. |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi there,
In my prev post i mentioned the COBOl function to do this.
For DB2
Code: |
Select Year ( Date(end_date) - Date(begin_date))
From Table1; |
|
|
Back to top |
|
|
vin12pr Warnings : 1 New User
Joined: 14 Jun 2006 Posts: 56
|
|
|
|
Hi,
Thanks Ekta for ur kind reply.....Does that cobol caluculation caluculates the difference in the number of years between the 2 dates?
I guess this is for number of days or months betweent the 2 dates??
Can you please expand a bit
Thanks,
Vinay |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
If you have the two dates, what's wrong with just subtracting the years from each other? |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi vin12pr,
By this u can get number of month between the two given dates then u can calculate number of years also. |
|
Back to top |
|
|
|