1

Closed

DateTime extension method

description

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 2:50 AM by JaCraig
Added the extension methods for TimeSpan and added functions to DateSpan class to basically accomplish this.

comments

JaCraig wrote Dec 24, 2011 at 6:33 PM

This is covered by the Subtract method on DateTime class:
http://msdn.microsoft.com/en-us/library/8ysw4sby.aspx

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...