Productivity

How to Calculate Time Duration Between Two Times (Even Overnight)

7 min read

To find the time between two clock times, convert both to minutes past midnight, subtract the start from the end, then divide by 60 for hours and minutes. If the end time is smaller than the start time, the span crosses midnight: add 24 hours to the end time before subtracting. The same logic runs in reverse when you add a duration to a start time to find a finish time, which can land on the next calendar day without you noticing.

Why simple subtraction breaks down

Clock time looks like ordinary arithmetic, but it isn’t, because it resets to zero every 24 hours. A shift that starts at 23:40 and ends at 06:15 didn’t shrink to a negative six hours and change. It ran through midnight, and the calculation has to account for that reset before the subtraction means anything.

The fix is mechanical once you see it. Convert both times to minutes since midnight (hours times 60, plus minutes). If the end value comes out lower than the start value, the span wrapped past midnight, so add 1,440 minutes (24 hours) to the end time first. Now the subtraction produces a normal positive number, which you split back into hours and minutes by dividing by 60 and taking the remainder.

The reverse operation, adding a duration to a start time, works the same way but in the other direction. Convert the start time to minutes, add the duration in minutes, and if the total exceeds 1,440, subtract 1,440 and note that the result falls on the next day. Subtracting a duration follows the mirror image: if the result drops below zero, add 1,440 and note that it falls on the previous day. Payroll software, flight schedules, and shift-planning tools all run this exact routine under the hood, they just hide the arithmetic behind a friendlier interface.

Two worked examples

Scenario A: an overnight shift. A security guard clocks in at 23:40 and clocks out at 06:15 the next morning. Subtract the raw clock times (06:15 minus 23:40) and you get a negative number, which is meaningless for a shift length. The end time is earlier than the start time only because the clock reset at midnight, not because the shift ran backwards.

Add 24:00 to the end time first: 06:15 becomes 30:15. Now subtract normally: 30:15 minus 23:40 equals 6 hours 35 minutes. That’s the actual length of the shift, and it matches what you’d get counting on your fingers from 23:40 to midnight (20 minutes) and then from midnight to 06:15 (6 hours 15 minutes), which also totals 6 hours 35 minutes.

Scenario B: adding a duration forward. A recipe’s active prep time starts at 16:20 and takes 2 hours 50 minutes. Add the duration directly to the start time: 16:20 plus 2:50 gives 19:10. No midnight crossing here, so no adjustment is needed, but the same 1,440-minute check would have applied automatically if the total had pushed past 24:00.

ScenarioStartEnd / DurationNaive resultCorrect result
A: overnight shift23:40ends 06:15negative / nonsensical6 hours 35 minutes
B: add a duration16:20+ 2h 50m19:10 (no adjustment needed)19:10

Scenario A needed the midnight correction because the end time was numerically smaller than the start time. Scenario B didn’t need it because 19:10 stayed comfortably within the same day, but if the prep had taken 8 hours instead of 2 hours 50 minutes, 16:20 plus 8:00 would land at 00:20, and a calculator that doesn’t check for the rollover would incorrectly show 24:20 instead of flagging that the job finishes just after midnight, on the next day.

Try it with your own numbers

Duration
--
Total hours
--
Total minutes
--
Time Duration Calculator
Free, no sign-up, works on any device.
Open the full tool

Common mistakes and edge cases

Subtracting an overnight end time directly. The single most common error is treating 06:15 minus 23:40 as a valid subtraction. It isn’t, until you add 24 hours to the end time to account for the day boundary the shift crossed. Skipping that step produces a negative or wildly wrong duration, and it’s easy to miss because the raw numbers still look like a normal time on the clock.

Forgetting a duration can push into the next day. Adding hours and minutes to a start time is straightforward until the total passes 24:00. A task that starts at 22:00 and takes 5 hours doesn’t finish at “27:00,” it finishes at 03:00 the following day. If you’re scheduling something and the finish time comes out looking like more than 24:00, that’s the calculation telling you to roll over to the next calendar day, not an error to round away.

Confusing this with a date difference. Calculating the gap between two clock times (like 23:40 and 06:15) is pure hours-and-minutes arithmetic within a 24-hour cycle. Calculating the gap between two calendar dates (like March 3 and September 14) is a different problem entirely, one that has to account for how many days are in each month and whether a February 29 falls inside the span. Mixing the two up, or trying to reuse one calculation for the other’s job, leads to answers that are subtly or drastically wrong.

Assuming time zones are handled automatically. A time duration calculation works on two clock readings as given, with no awareness of where either clock is located. If a call starts at 9:00 in one city and ends at 17:00 according to a clock in a different time zone, the raw subtraction between those two numbers means nothing until both times are converted to the same reference zone first. The calculator assumes you’ve already done that and both times belong to the same clock.

Frequently asked questions

What happens when the span crosses midnight? The calculation detects it automatically: if the end time is numerically earlier than the start time, 24 hours get added to the end time before the subtraction runs, which turns an apparently negative result into the correct overnight duration.

Can it add or subtract a duration from a start time instead of comparing two times? Yes, that’s the reverse of the same operation. Give it a start time and a duration to add or subtract, and it works out the resulting time, including flagging when that result rolls onto the next or previous day.

Does the calculation know about calendar dates? No, and that’s intentional. It only works with clock time within a 24-hour cycle. If you need the gap between two actual dates, months and leap years included, that calls for a date difference calculator instead, since the two problems use completely different logic.

Are time zones factored in anywhere? No. Both times you enter are assumed to already be in the same time zone. If you’re comparing times from two different zones, convert one of them to match the other before running the calculation, otherwise the result won’t reflect anything real.

Can I share a link with my times already filled in? On the calculator’s own page, yes, your inputs sync into the URL so sending the link opens the tool with the same times pre-loaded. Inside an embedded widget like the one in this article, that URL syncing is turned off, since there’s no separate page address to update.

What if I need to add up several durations, not just one? Run the calculation in sequence: take the result of the first addition as the new start time and add the next duration to it, repeating for each duration in the chain. The same midnight-rollover check applies at every step, so a long chain of short tasks can still end up finishing a day or more after it started.

Time calculationsSchedulingDurationTime management
Time Duration Calculator
Now try it yourself with the full tool.
Try it now