Calculate the TotalMonths difference between two DateTime
-
just wondering if someone has implemented something that calculates the TotalMonths (or Weeks or Years) between two DateTime values. The TimeSpan class obviously provides things like TotalDays, TotalMinutes and the like but as it doesn't have any reference to a DateTime it can't give you the TotalMonths, TotalWeeks or TotalYears. has anyone done that already?
-
just wondering if someone has implemented something that calculates the TotalMonths (or Weeks or Years) between two DateTime values. The TimeSpan class obviously provides things like TotalDays, TotalMinutes and the like but as it doesn't have any reference to a DateTime it can't give you the TotalMonths, TotalWeeks or TotalYears. has anyone done that already?
It doesn't probably because "month" is rather ambiguous. Is it 28 days if the starting date fall in Feb, or the ending date fall in Feb? Or Feb is in the middle of the data range? Probably the same for "Year". How about leap years? For weeks, you can divide total days by 7.
-
just wondering if someone has implemented something that calculates the TotalMonths (or Weeks or Years) between two DateTime values. The TimeSpan class obviously provides things like TotalDays, TotalMinutes and the like but as it doesn't have any reference to a DateTime it can't give you the TotalMonths, TotalWeeks or TotalYears. has anyone done that already?
just discovered that the (VB.NET) DateAndTime class has a method called DateDiff which calculates such things...