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

11,880

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

Share:
11,880
сами J.D.
Author by

сами J.D.

Updated on June 14, 2022

Comments

  • сами J.D.
    сами J.D. almost 2 years

    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.

  • сами J.D.
    сами J.D. over 7 years
    This is what I was looking for. I was finding lots of complicated examples, no idea why, when with this function, we have everything. Thanks mate.