Quantcast
Viewing latest article 2
Browse Latest Browse All 46

Answer by Gambitier for Difference in months between two dates

Apart from all given answers I find this piece of code very straightforward. AS DateTime.MinValue is 1/1/1, we have to subtract 1 from month, years and days.

var timespan = endDate.Subtract(startDate);var tempdate = DateTime.MinValue + timespan;var totalMonths = (tempdate.Year - 1) * 12 + tempdate.Month - 1;var totalDays = tempdate.Day - 1;if (totalDays > 0){    totalMonths = totalMonths + 1;}

Viewing latest article 2
Browse Latest Browse All 46

Trending Articles