I was wondering how I can get the difference between two dates in complete hours
e.g.
DateTime date1 = DateTime.Now;
DateTime date2 = new DateTime(2011, 8, 5, 33,00);
long hours = date1 - date2;
It's the cast to long/int that will give you complete hours.
TimeSpan span = date1.Subtract(date2);
long hours = (long)span.TotalHours;
var hours = (date1 - date2).TotalHours;
Or, if you don't want the fraction of an hour:
var hours = Math.Floor((date1 - date2).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