Posted by Alec on Tue, 08 Sep 2009, in ASP.NET C#
I recently needed to show a datetime as amount of time left or past. This can be done by using TimeSpan, which you can get by subtracting one DateTime from another:
DateTime dt1 = new DateTime(2009, 7, 2); DateTime dt2 = new DateTime(2009, 7, 3); TimeSpan difference = dt2 - dt1; // Then you can display things like difference.Days
See the docs on TimeSpan: http://msdn.microsoft.com/en-us/library/system.timespan.aspx