Skip to content
2xKit

How to Calculate Hours Worked From Clock-In and Clock-Out Times (Including Overnight Shifts)

The correct way to calculate total hours worked from time-of-day entries, including the overnight shift edge case that breaks simple subtraction.

Quick answer

Hours worked is calculated by converting clock-in and clock-out times into minutes since midnight and subtracting, but for overnight shifts where the clock-out time is numerically smaller than the clock-in time (like in at 10 PM, out at 6 AM), you have to add 24 hours to the clock-out time before subtracting, otherwise the result comes out negative. The Hours Worked Calculator handles this automatically for both same-day and overnight shifts.

Calculating hours worked from a clock-in and clock-out time looks trivial for a normal daytime shift, just subtract the earlier time from the later one, but that same simple subtraction silently breaks for any shift that crosses midnight. Since payroll and scheduling systems both rely on getting this number exactly right, it's worth understanding why the overnight case needs different handling.

The straightforward case

For a same-day shift, say clock-in at 9:00 AM and clock-out at 5:30 PM, converting both times to minutes since midnight (540 and 1050 respectively) and subtracting gives 510 minutes, or 8.5 hours. This works fine as long as the clock-out time is later in the day than the clock-in time, which covers the majority of shifts but not all of them.

Why overnight shifts break simple subtraction

A shift that starts at 10:00 PM and ends at 6:00 AM the next morning is a real 8-hour shift, but converting both to minutes since midnight gives 1320 for the clock-in and 360 for the clock-out. Subtracting the smaller from the larger the naive way (360 minus 1320) produces a negative number, which is obviously wrong for a duration. The fix is to detect that the clock-out time is numerically earlier than the clock-in time, treat that as a signal the shift crossed midnight, and add 24 hours (1440 minutes) to the clock-out value before subtracting, giving the correct 480 minutes, or 8 hours.

This overnight case is one of the most common bugs in hand-rolled timesheet spreadsheets, since a formula that works perfectly for every daytime entry will silently return a negative or nonsensical number the first time someone enters a night-shift pair. The Hours Worked Calculator detects and handles the overnight case automatically, so you don't need a separate formula for night shifts.

Unpaid breaks and rounding

Once you have the raw duration, most workplaces subtract unpaid break time (a 30-minute or 60-minute lunch, for example) to get paid hours, and some also round the clock-in/clock-out times themselves to the nearest interval before calculating, a practice covered in detail in our guide on time card rounding rules. If you need the duration between two arbitrary timestamps rather than a work shift specifically, the general-purpose Time Duration Calculator handles that broader case.

Frequently asked questions