简体   繁体   中英

Excel: Calculate the difference between two times

Is there an Excel function to calculate the difference between two times? I can't find anything that would work if the first time is yesterday or less than the second time.

在此处输入图片说明

Times in Excel for Windows are represented as a fractional number of days from the beginning of January 1st, 1900. To compute the difference between two times or dates, all you have to do is subtract the two. You can then multiply the result to convert from days into the units you want. (ie: *24 to get hours, *1440 to get minutes, *86400 to get seconds, etc.)

Technically speaking, older versions of Excel for the Mac defaulted to the 1904 date system, which used January 1st, 1904 as the first day. The 1904 date system can be enabled even in Windows Excel using a setting in the advanced tab of the Excel options dialog. (Right next door to Lotus 1-2-3 compatibility and DDE configuration.)

Elegant way to do this is:

=MOD(finish-start,1)*24

If start and finish time are on the same day the MOD function does not change anything. If time crosses midnight and finish is earlier then start, the MOD function flips the sign of the difference.

Note that this formula calculates the difference between two times (actually two dates) as decimal value. You should display the result as time.

https://exceljet.net/formula/time-difference-in-hours-as-decimal-value

This is a good article that quickly explains how excel deals with times regarding a difference between two times, and what to do if they fall on either side of midnight.

Difference between two times

The formula given is =MOD((end_time - start_time)+1,1)

There's a follow up on how to convert times into decimal

How to convert times into hours, minutes or seconds (decimal)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM