Tuesday, 23 September 2008

Get the TimeSpan between two DateTimes

The task was to calculate the time different between two dates.

After surfing arround on the internet once again I found that there is a TimeSpan structure. This represents a time interval.

TimeSpan is used to find the difference between two dates and are used this way:

TimeSpan newTimeSpan = DateTime.Now - inputDateTime;

There are many usable properties in TimeSpan:
newTimeSpan.TotalDays
newTimeSpan.TotalHours
newTimeSpan.TotalMinutes.

Read more about TimeSpan on MSDN
http://msdn.microsoft.com/en-us/library/system.timespan.aspx

No comments: