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

Finding the number of years from two dates


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vin12pr
Warnings : 1

New User


Joined: 14 Jun 2006
Posts: 56

PostPosted: Mon Dec 11, 2006 5:43 pm
Reply with quote

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
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Mon Dec 11, 2006 6:17 pm
Reply with quote

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
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Mon Dec 11, 2006 6:25 pm
Reply with quote

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
View user's profile Send private message
vin12pr
Warnings : 1

New User


Joined: 14 Jun 2006
Posts: 56

PostPosted: Mon Dec 11, 2006 6:37 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Mon Dec 11, 2006 6:39 pm
Reply with quote

If you have the two dates, what's wrong with just subtracting the years from each other?
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Mon Dec 11, 2006 6:53 pm
Reply with quote

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
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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Finding and researching jobs All Other Mainframe Topics 0
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts VB to FB - Finding LRECL SYNCSORT 4
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top