How to calculate the time difference
-
How to calculate time difference in hours between two dates, let's say 01/01/01 12:00 and 02/02/07 7:00?
-
How to calculate time difference in hours between two dates, let's say 01/01/01 12:00 and 02/02/07 7:00?
Just use the
DateTime.Subtract
function, like so:Dim FirstDate As New DateTime(2007, 2, 2, 7, 0, 0)
Dim SecondDate As New DateTime(2001, 1, 1, 12, 0, 0)
Dim FinalDate As TimeSpan = FirstDate.Subtract(BDayNow)Hope this helps!
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
How to calculate time difference in hours between two dates, let's say 01/01/01 12:00 and 02/02/07 7:00?
You can subtract DateTime values, the result is a TimeSpan. You can use the TotalHours property to get the time difference. Example:
Dim startTime as DateTime = new DateTime(1, 1, 1, 12, 0, 0) Dim endTime as DateTime = new DateTime(7, 2, 2, 7, 0, 0) Dim diff as TimeSpan = endTime - startTime Dim hours as Double = diff.TotalHours;
--- single minded; short sighted; long gone;
-
How to calculate time difference in hours between two dates, let's say 01/01/01 12:00 and 02/02/07 7:00?