static DateTimeSpan GetDateDiff(DateTime startDate, DateTime endDate) { int year = endDate.Year; int month = endDate.Month; TimeSpan startSpan = new TimeSpan(startDate.Day, startDate.Hour, startDate.Minute, startDate.Second); TimeSpan endSpan = new TimeSpan(endDate.Day, endDate.Hour, endDate.Minute, endDate.Second); if (endSpan - startSpan < new TimeSpan(0)) { month -= 1; if (month == 0) { month = 12; year -= 1; } } TimeSpan ts = endDate.Subtract(new DateTime(year, month, startDate.Day, startDate.Hour, startDate.Minute, startDate.Second)); DateTimeSpan dts = new DateTimeSpan(year - startDate.Year, month - startDate.Month, ts.Days, ts.Hours, ts.Minutes, ts.Seconds); if (dts.Months < 0) { dts.Months = 12 + dts.Months; dts.Years = dts.Years - 1; } return dts; }