Calculate time difference in excel

筅森魡賤 提交于 2019-12-02 08:07:16

Try this to include the spelled out hours and minutes:

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

Note that since the m comes immediately (ignoring the separator text in quotes) after the h it will be interpreted as minutes and not months

I prefer to work with dates as decimals. It looks cumbersome, but I'm much happier knowing what it's doing.

What I would usually do is to have A1-A2 in cell A3, then work out the component parts separately:

Days: =INT(A3)
Hours: =INT((A3-INT(A3))*24)
Minutes: =INT(((A3*24)-INT(A3*24))*60)

Or if you wanted to do it all in one formula:

=INT(A3)&" days, "&INT((A3-INT(A3))*24)&" hours, "&INT(((A3*24)-INT(A3*24))*60)&" min"

or without using A3

=INT(A1-A2)&" days, "&INT(((A1-A2)-INT(A1-A2))*24)&" hours, "&INT((((A1-A2)*24)-INT((A1-A2)*24))*60)&" min"

It's not the prettiest or most efficient method but you can see how the times are calculated this way.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!