Petes techie blog

A blog written for two people. Me and You.

Difference Between Dates in Whole Months

| Comments

1
2
3
4
5
6
7
8
9
10
11
// No of years * 12 + no of months + (-1) if startday is greater than endDay
private static int monthDifference(DateTime startDate, DateTime endDate)
{

int monthsApart = 12 * (endDate.Year - startDate.Year) +

endDate.Month - startDate.Month + ((startDate.Day - endDate.Day > 0) ? -1 : 0);

return monthsApart;

}