Page 1 of 1

Number of months between two dates

Posted: Thu Sep 15, 2011 11:51 am
by reddyamarnath
Hi
can any one please help me how to calculate the number of months between two dates.

Thanks

Posted: Thu Sep 15, 2011 12:36 pm
by Etler21
you can use MonthfromDate() function to get month out and then subtract.

Posted: Thu Sep 15, 2011 9:28 pm
by qt_ky
That may depend on your requirements and definition on month: 28, 29, 30, or 31 days? How many months would you say are between Jan. 31 and Feb. 1? How many between Jan. 31 and Mar. 1? etc.

Posted: Thu Sep 15, 2011 11:20 pm
by jwiles
One method that worked for a client several years ago was:

Code: Select all

(Year1 - Year2) * 12 + (Month1 - Month2) + (if Day1 >= Day2 then 1 else 0)
where Date1 is the later of the two dates (Year1, Month1, Day1). That particular client didn't care about the number of days in the month for the calculation. How you extract Year, Month and Day will depend on the format of your dates.

Regards,