Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate time difference between two dates (DD/MM/YYY HH/MM)

Tags:

date

excel

vba

In Excel, I have these kind of fields (in the second and the third column):

Fecha/Hora inicio   Fecha/Hora finalización
02/01/2017 21:32    03/01/2017 6:02
02/01/2017 6:02     03/01/2017 7:32
03/01/2017 7:38     04/01/2017 13:47

I want to know the time difference between the first and the second field in hours. For instance, in the second case, the difference is 25.5 hours.

I was trying to calculate it manually but I'm sure there is an automatic way.

like image 467
сами J.D. Avatar asked Jan 27 '26 04:01

сами J.D.


1 Answers

VBA has a function called DateDiff which measures the difference between two dates in terms of a specified unit (anything from years to seconds). For this case, we will need to measure in minutes because we want to measure fractions of an hour and then divide by 60 to get back to hours. If we only wanted whole hours then we could measure in hours instead.

The following should provide the required result:

MsgBox DateDiff("n", "02/01/2017 6:02", "03/01/2017 7:32") / 60

"n" is the interval specifier for minutes in the DateDiff function

like image 143
barrowc Avatar answered Jan 31 '26 15:01

barrowc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!