Calculating the difference between two time stamps

Excel 365 2016 2013 2007 2003
Because time stamps are represented as serial numbers, you can subtract the earlier time from the later time to get the difference.

For example, if cell A2 contains 9:00:00 and cell B2 contains 17:30:00, the following formula returns 08:30:00 (a difference of eight hours and 30 minutes):

= B2 - A2

Formula in Excel 2010

If the subtraction results in a negative value, however, it becomes an invalid time; Excel displays a series of hash marks (#######) because a time without a date has a date series number of 0. A negative time results in a negative series number, which is not permitted.

If the direction of the time difference doesn't matter, you can use the ABS function to return the absolute value of the difference:

= ABS (B3 - A3)

ABS Formula in Excel 2010

This negative time problem often occurs when calculating an elapsed time - for example, calculating the number of hours worked given a start time and an end time. This presents no problem if the two times fall in the same day. But if the work shift spans midnight, the result is an negative time.

For example, you may start work at 08:00 PM and end work at 5:00 AM the next day. Using the ABS function (to calculate the absolute value) isn't an option in this case because it returns the wrong result (15 hours). The following formula, however, does work:

= IF (B3 < A3, B3 + 1, B3) - A3

IF Formula in Excel 2010

In fact, another formula (even simple) can do the job:

= MOD (B3 - A3, 1)

Please, disable AdBlock and reload the page to continue

Today, 30% of our visitors use Ad-Block to block ads.We understand your pain with ads, but without ads, we won't be able to provide you with free content soon. If you need our content for work or study, please support our efforts and disable AdBlock for our site. As you will see, we have a lot of helpful information to share.