How to Calculate Hours Between Two Times, Even Overnight
Subtracting times looks like ordinary subtraction, but it is done in base 60 and the clock wraps around at midnight. That is why 17:05 minus 09:40 does not give 7:65, and why a shift from 22:15 to 06:40 seems to produce a negative number.
The most dependable fix is to turn each time into minutes, subtract once, and convert back at the end. This article walks through that method, the overnight case, deducting breaks, an alternative borrowing method, and the situations where plain subtraction gives the wrong answer.
The minutes-since-midnight method
Convert each time to the number of minutes since 00:00 using hours × 60 + minutes, subtract the earlier from the later, then split the result into hours and minutes.
minutes = (end hours × 60 + end minutes) − (start hours × 60 + start minutes)Use 24-hour times, so 5:05 PM is 17:05.
Worked example: 09:40 to 17:05. Start: 9 × 60 + 40 = 580. End: 17 × 60 + 5 = 1,025. Difference: 1,025 − 580 = 445 minutes. Divide by 60: 7 remainder 25, so 7 hours 25 minutes.
When the shift crosses midnight
If the end time looks earlier than the start time, the span runs past midnight into the next day. Add 1,440 minutes (24 hours) to the end before subtracting.
Worked example: 22:15 to 06:40. Start: 22 × 60 + 15 = 1,335. End: 6 × 60 + 40 = 400. Subtracting gives 400 − 1,335 = −935, which is negative. Add 1,440: −935 + 1,440 = 505 minutes, which is 8 hours 25 minutes.
You can confirm it by splitting at midnight. From 22:15 to 24:00 is 1 hour 45 minutes, and from 00:00 to 06:40 is 6 hours 40 minutes. Together that is 7 hours 85 minutes, which is 8 hours 25 minutes.
Deducting breaks
Subtract unpaid breaks from the total in minutes before converting. Using the overnight shift above with a 30-minute unpaid break: 505 − 30 = 475 minutes, which is 7 hours 55 minutes, or 7.92 hours in decimal form (475 ÷ 60 = 7.9167).
Whether a break is paid or unpaid depends on the employer's policy and local rules, so apply whatever your own arrangement says. For payroll the decimal form is usually what gets multiplied by the rate, and the time to decimal converter does that step in one go.
The borrowing method for h:mm times
If you prefer to subtract the hours and minutes columns directly, borrow from the hours when the minutes go negative, just as in column subtraction. Borrowing here means 60 minutes, not 10.
Worked example: 17:05 − 09:40. Hours: 17 − 9 = 8. Minutes: 5 − 40 = −35. The minutes are negative, so borrow one hour: hours become 7, and minutes become −35 + 60 = 25. The answer is 7 hours 25 minutes, matching the method above.
When plain subtraction gives the wrong answer
- 12-hour clock mix-ups. Convert to 24-hour times first. 12:30 AM is 00:30 and 12:30 PM is 12:30.
- Identical start and end times. Zero hours or 24 hours? Neither answer is automatic, so state which you mean.
- Spans longer than a day. Include the dates, not just the times, or you will lose whole days.
- Clock changes. On a night when the clocks change for daylight saving, a 22:00 to 06:00 shift is 7 or 9 hours of real time, not 8.
- Time zones. Times written in different zones cannot be subtracted directly.
Worked example, a flight: a flight leaves London at 10:00 and lands in New York at 13:00 local time, in January. The naive difference is 3 hours, which is wrong. London is UTC+0 and New York is UTC−5, so the landing time is 18:00 UTC. The flight lasts 18:00 − 10:00 = 8 hours. Convert both ends to the same zone first; the guide to converting time zones using UTC offsets shows how.
The hours calculator finds the time between two clock times, the time calculator adds and subtracts durations, and the time card calculator totals a week of shifts with breaks.
- Hours Calculator: Enter a start time, an end time and an optional break to get the time in between as hours and minutes, decimal hours and total minutes. A second mode handles two full dates with times.
- Time Calculator: Use the clock calculator to see what time it will be after adding or removing hours, minutes and seconds, or the date and time calculator to move a whole timestamp forwards or backwards.
- Time Card Calculator: Pick a period of one to 31 days, enter when you clocked in, clocked out and how long you took for breaks, and the calculator totals your hours. Add an hourly rate and an overtime rule to see regular, overtime and gross pay.
This article is general information, not professional advice. See our Disclaimer and Editorial Policy.
More articles
How to Convert Between Time Zones Using UTC Offsets
Skip the guesswork: convert the local time to UTC, then to the target zone. Includes half-hour offsets, date changes and a worked meeting-overlap example.
12-Hour to 24-Hour Time: Conversion Rules and Common Slips
Two rules cover every conversion between AM/PM and the 24-hour clock. Here they are, with a reference table, midnight and noon explained, and the usual mistakes.
Daylight Saving Time: Why Some Days Have 23 or 25 Hours
When clocks change, a local day is no longer 24 hours. Learn what shifts, how it alters durations and meeting times, and how to calculate safely.