Excel: How to calculate time differences beyond midnight

Suppose you have a document with a date and time column. Calculating time differences is easy, you can simply subtract an earlier time from a later one1. In the screenshot below, column C shows the difference between the time in consecutive rows (column B). However, you can see that this simple approach fails just after midnight:

The time difference in row 4 is negative and also wrong. This becomes very clear when you switch to a 24h time format and enable negative times2: Did you notice that the dates in column A have changed? This was due to the method I used to enable negative time values (see note 2 below).

Solution: Include the date in the calculation

Internally, dates are represented as whole numbers and times as fractional numbers smaller than 1 (1 would be 24h = 1 whole day). This means you can simply add date and time! Therefore, a better formula to calculate time differences is:

=A2+B2-(A1+B1)

By including the date, this formula works fine after midnight.

What if you don’t have a date column?

You can use a clever approach I found here: