Calculate time difference in excel

后端 未结 3 1589
梦毁少年i
梦毁少年i 2021-01-28 13:11

I have a two dates in excel \"1/2/2016 01:56:05\" and \"8/3/2016 06:21:46\". How do I calculate the time difference between them in a format of days and hours?

Thanks!

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-28 13:24

    Assuming the dates are in cells A1 and A2, this will produce an answer with minutes as well in d:hh:mm format.

    =INT(A2-A1) & ":" & TEXT(A2-A1,"hh:mm")
    

    Drop the :mm if you don't need minutes.

    If you want text:

    =INT(A2-A1) & " days, " & TEXT(A2-A1,"h") & " hours"
    

    If you want text with minutes:

    =INT(A2-A1) & " days, " & TEXT(A2-A1,"h"" hours, ""m"" minutes""")
    

    Using double quotes alongside each other "escapes" the quote itself and allows the extra text to appear in the string. As Ron stated in his answer, the m following an h in the same format string indicates minutes, so you can save an extra A2-A1 calculation by putting both in a single format.

提交回复
热议问题