Number of months between two dates

Stimulsoft Reports.NET discussion
Post Reply
MikeC
Posts: 51
Joined: Mon Jun 07, 2010 3:36 pm

Number of months between two dates

Post 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.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Number of months between two dates

Post 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.

MikeC
Posts: 51
Joined: Mon Jun 07, 2010 3:36 pm

Number of months between two dates

Post by MikeC »

That worked well enough. Thank you.
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

Number of months between two dates

Post by Andrew »

Great!

Have a nice weekend!
Thank you.
Post Reply