How can I subtract two dates and get the total hours of the TimeSpan
object that is returned?
For example, if the TimeSpan is 2 days, the total hours are 48.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With