Reputation: 21
I need help with calculating time difference between times from two different dates.
Cell(1,1) contains: 19/06/2016 01:00:00
Cell(1,2) contains: 20/06/2016 02:30:00
The answer should be: 25:30:00 Following is my code:
Dim a As Date, b As Date
a = Cells(1, 1).Value
b = Cells(1, 2).Value
Cells(1, 3).Value = TimeValue(b) - TimeValue(a)
But this code gives me 1:30:00
Upvotes: 1
Views: 4157
Reputation: 96791
Just subtract:
Sub luxation()
Dim a As Date, b As Date
a = Cells(1, 1).Value
b = Cells(1, 2).Value
Cells(1, 3).Value = b - a
Cells(1, 3).NumberFormat = "[hh]:mm:ss"
End Sub
Upvotes: 4