How to Calculate Hours Between Two Times (Even Overnight)
By WorkCalc Team · August 10, 2026
Figuring out how many hours passed between a start time and an end time sounds trivial, until the shift crosses midnight and simple subtraction gives you a negative number. The good news is that the fix is a single rule, and once you know it, the math takes seconds by hand or instantly with a calculator.
The core idea: minutes since midnight
The trick to comparing two clock times reliably is to stop thinking in “hours and minutes” and convert each time into a single number: minutes since midnight. A time of 9:00 AM becomes 9 x 60 = 540 minutes. A time of 5:30 PM (17:30 in 24 hour format) becomes 17 x 60 + 30 = 1,050 minutes. Once both times are plain numbers, finding the gap between them is ordinary subtraction.
This is exactly what the Hours Between Calculator does under the hood. It takes your start time and end time, each in 24 hour “HH:MM” format, converts both to minutes since midnight, and subtracts. The only complication is what happens when the end time’s minute count is smaller than the start time’s, which happens whenever a shift runs past midnight into the next day.
The formula
Start Minutes = Start Hour x 60 + Start Minute
End Minutes = End Hour x 60 + End Minute
Difference = End Minutes - Start Minutes
If Difference < 0:
Difference = Difference + 1440 (add 24 hours, in minutes)
Hours = floor(Difference / 60)
Minutes = Difference mod 60
Decimal Hours = Difference / 60
That “add 1,440 minutes if the result is negative” step is the entire overnight rule. There’s no separate toggle to flip or checkbox to tick for a shift that crosses midnight; the calculator just assumes that when the end time is earlier in the day than the start time, the end time actually happened the following day, and adjusts automatically.
Worked example: a daytime shift
Say you clocked in at 9:00 AM and clocked out at 5:30 PM. Converting to minutes since midnight:
- Start: 9:00 AM = 540 minutes
- End: 5:30 PM = 1,050 minutes
- Difference: 1,050 - 540 = 510 minutes
Since 510 is positive, no adjustment is needed. Convert back to hours and minutes: 510 / 60 = 8 hours, with a remainder of 510 - (8 x 60) = 30 minutes. That gives 8 hours 30 minutes, or 8.50 decimal hours if you need a single number for payroll or a spreadsheet formula. No wraparound involved, just a straightforward subtraction.
Worked example: an overnight shift
Now try a graveyard shift that starts at 10:00 PM and ends at 6:00 AM the next morning. Converting to minutes since midnight:
- Start: 10:00 PM = 22:00 = 1,320 minutes
- End: 6:00 AM = 06:00 = 360 minutes
- Difference: 360 - 1,320 = -960 minutes
That negative number is the signal that the end time belongs to the next day. Add 24 hours (1,440 minutes) to correct it: -960 + 1,440 = 480 minutes. Convert back: 480 / 60 = 8 hours exactly, with 0 minutes left over. So the shift lasted 8 hours 0 minutes, or 8.00 decimal hours. Without the overnight adjustment, you’d get a nonsensical negative duration; with it, the answer matches what anyone glancing at a clock would expect.
When this approach isn’t enough
Converting to minutes since midnight and wrapping past zero works well for a single shift that starts and ends within a 24 hour window, which covers the overwhelming majority of time cards and appointment lengths. But it has a real limit: it has no concept of a specific calendar date, only a time of day. If a start time and end time are more than 24 hours apart, this method can’t tell the difference between “10 hours” and “34 hours”; it will always wrap to the shorter interval within a single day.
That matters if you’re tracking something like a multi-day on-call rotation, a project that spans several calendar days, or any duration where the actual dates (not just the clock times) are part of the answer. For those cases, reach for the Time Duration Calculator instead. It takes a start date and end date along with the times, so it can correctly report a span of, say, 2 days and 3 hours rather than collapsing everything into a same-day or next-day guess. Use the Hours Between Calculator when you only care about two points on a clock face; use Time Duration when the calendar matters too.
FAQ
Does the calculator need me to specify AM/PM? No. It uses 24 hour “HH:MM” input (from a standard time picker), so 5:30 PM is entered as 17:30 and 10:00 PM as 22:00. That format avoids any AM/PM ambiguity and is what the minutes-since-midnight math expects.
What happens if I enter the same time for both start and end? The difference comes out to zero minutes, so the result is 0 hours 0 minutes (0.00 decimal hours), rather than being treated as a full 24 hour span. The calculator only adds a day when the end time is strictly earlier than the start time.
Can I use this for a shift longer than 24 hours? Not directly. Because the calculator only knows times of day, not dates, it assumes any span it’s given fits within one wraparound of 24 hours. For anything longer, or where the exact calendar dates matter, use the Time Duration Calculator instead.
Use the Hours Between Calculator to run your own numbers.