Calculate number of months between two dates

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
murur
Participant
Posts: 19
Joined: Wed Apr 14, 2004 7:55 am

Calculate number of months between two dates

Post by murur »

I have two date column, how do i derive number of months between two dates
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

First thing would be to define what you mean by 'month'. Second would be to search the forum as this isn't the first time someone asked this question. For example, some answers here.
-craig

"You can never have too many knives" -- Logan Nine Fingers
WoMaWil
Participant
Posts: 482
Joined: Thu Mar 13, 2003 7:17 am
Location: Amsterdam

Post by WoMaWil »

You have to calculate the difference with a routine.

If you use the DataStage internal date-format the date is a number and you can substract both "number"s and proceed:

For example divide through 30.437500 and round it, round it up, round it down, leave the part after the period.

You can programm what you want, but you need to programm something or you get the routine from somebody who has already programmed such an routine.

Kind regards
Wolfgang
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Completed months (always integer) or partial months?

For example, what would be your expected result if the two dates were 2004-01-02 and 2005-03-15 ? Your choices are 14 or 14.4.

A routine is needed to handle the situation where the day number of the first month is larger than the last day of the second month. For example would would be your expected result if the two dates were 2004-01-29 and 2005-02-28 ? February 2005 is complete in this case.

Whatever your specification (your business rule) that's how you code your Routine, and you use the Long Description and comments in the code to explain to future developers that such is the rule being implemented in this case. If you're a contractor, also get your client to sign off agreement that this is how they want "months between two dates" interpreted.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply