How to Count Employees Working Each Hour in Excel (Including Midnight Shifts)
Question details
The user needs to calculate the number of employees working during each hour of the day based on employee schedules.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Calculating hourly staffing coverage for a business schedule, specifically handling complex shifts that cross midnight and excluding 30-minute unpaid lunch breaks.
- Observed behavior
- Standard time difference calculations fail when a shift crosses midnight (e.g., 22:00 to 06:00), making it difficult to aggregate active working minutes against a continuous 24-hour timeline.
Ensure all your start and end times are formatted as proper Excel Time values (e.g., hh:mm) and not as plain text to allow formula calculations to evaluate them correctly.
Use Date-Time Conversion and Array Formulas to Count Staff
Convert shift times into continuous date-time values to easily calculate overlaps. By adding a day to shifts that cross midnight, you can compare the shift against a standard 24-hour timeline.
Calculating hourly coverage requires breaking the day into specific hour blocks and checking if each employee's shift overlaps with that block. The biggest challenge is handling overnight shifts, which requires a mathematical adjustment to represent the next day correctly.
Set up your worksheet with columns for 'Employee', 'Start Time', 'End Time', and 'Lunch Break'. Verify that the time entries are valid time formats.
Create a new column named 'Adjusted End Time'. Enter the formula `=IF(C2<B2, C2+1, C2)` (assuming B2 is Start Time and C2 is End Time). This adds 1 day (24 hours) to any shift ending earlier than it started, converting it into a continuous timeline.
In a separate area of your sheet, create a horizontal row containing the hours of the day (e.g., 0:00, 1:00, 2:00... up to 23:00) to represent each hour block you want to analyze.
Use an array formula or `SUMPRODUCT` under each hour block to evaluate if the timeline hour falls within the employee's adjusted shift. A basic logic structure checks `(Start_Time <= Hour_Block) * (Adjusted_End_Time > Hour_Block)`.
If you know the exact lunch break interval, subtract it from the overlap calculation. If simply totaling hours, ensure you subtract `TIME(0, 30, 0)` from the employee's total working shift duration.

Easily Calculate Staffing Levels in WPS Spreadsheet
WPS Spreadsheet offers powerful date and time functions, making it simple to manage complex employee schedules, handle midnight shifts, and accurately calculate hourly coverage.
- 1. Open Your Schedule Data: Launch WPS Spreadsheet and open your employee shift workbook.
- 2. Format Time Cells: Highlight your time columns, right-click, select 'Format Cells', and ensure the 'Time' category is applied.
- 3. Apply Shift Adjustments: Use the formula `=IF(End<Start, End+1, End)` to seamlessly adjust any overnight working shifts.
- 4. Calculate the Timeline: Utilize built-in `COUNTIFS` or `SUMPRODUCT` formulas across your hourly columns to automatically count active employees per hour.

Frequently Asked Questions
How do I handle a shift that ends the next day in an Excel formula?
When calculating time differences, a shift that ends the next day will result in a negative number. You can fix this by using the formula `=MOD(End_Time - Start_Time, 1)` or `=IF(End_Time < Start_Time, End_Time + 1, End_Time)` to correctly calculate the duration.
Can I deduct exactly 30 minutes for a lunch break in Excel?
Yes. Since Excel stores time as a fraction of a 24-hour day, you can subtract 30 minutes by using the TIME function: `- TIME(0, 30, 0)` at the end of your duration calculation.
What is the best function to count occurrences across specific time ranges?
The `COUNTIFS` function is ideal for simple overlap counting. However, for more complex conditions—like checking arrays, adjusting for next-day shifts inline, and excluding overlapping lunch intervals—the `SUMPRODUCT` function provides more flexibility.




