Page 1 of 1

Number of months between two dates

Posted: Thu Nov 18, 2010 1:34 pm
by MikeC
I have two date fields and I need to determine the number of months between them. I couldn't find anything in the documentation nor could I find anything when searching the forum.

For example, I have 6/1/2009 and 12/31/2009 I need to return a 7 (number of months between the two dates inclusive of them).

Thank you.

Number of months between two dates

Posted: Fri Nov 19, 2010 1:46 am
by Alex K.
Hello,

You can use the following code for approximate calculation of the difference in months (with some calculating error)
{Round((double)DateDiff(Date1,Date2).Days/30)}

For an accurate calculation you would need to realize your own method that calculates the difference between years, months, days and calculate the result.

Thank you.


Number of months between two dates

Posted: Fri Nov 19, 2010 1:48 pm
by MikeC
That worked well enough. Thank you.

Number of months between two dates

Posted: Fri Nov 19, 2010 11:34 pm
by Andrew
Great!

Have a nice weekend!
Thank you.