DateTime extension method


Create a DateTime extension method that calculates the diff between two Dates expressed in Year+Month+Day+Hour+Minute+Second.
Could also be used to calculate a person's age (DateTime.Now - DateOfBirth).
Closed Dec 25, 2011 at 1:50 AM by JaCraig
Added the extension methods for TimeSpan and added functions to DateSpan class to basically accomplish this.


JaCraig wrote Dec 24, 2011 at 5:33 PM

This is covered by the Subtract method on DateTime class:

The Subtract method returns a TimeSpan object that shows the difference. However the TimeSpan object doesn't have an easy Months or Years properties (but it can be calculated by the Days property). This might be better as additions to the DateSpan class and extensions to the TimeSpan class...