Difference between two DateTimes C#?
I need a function that can return the difference between the below two dates as 24. DateTime a = new DateTime(2008, 01, 02, 06, 30, 00); DateTime b = new DateTime(2008, 01, 03, 06, 30, 00); You can do the following: TimeSpan duration = b - a; There's plenty of built in methods in the timespan class to do what you need, i.e. duration.TotalSeconds duration.TotalMinutes More info can be found here . Try the following double hours = (b-a).TotalHours; If you just want the hour difference excluding the difference in days you can use the following int hours = (b-a).Hours; The difference between these