tags:

views:

119

answers:

1

Hi,

i want to subtract two dates and get the total hours of the TimeSpan object that it's returned. For example, if the TimeSpan is of 2 days, the total hours are 48.

Thanks

+4  A: 

Then you want the TotalHours property of the TimeSpan object:

DateTime today = DateTime.Today;
DateTime twoDaysAgo = today.AddDays(-2.0);

// returns 48.0
double totalHours = (today - twoDaysAgo).TotalHours;
Dan Tao