Excel Formula to Calculate Hours Worked Within a Time Slot
Question details
The user needs to calculate the number of working hours that overlap with a specified time range, such as a three-hour window used for FTE availability planning.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Comparing employee shift schedules against specific time blocks to determine precise overlapping working hours for resource allocation.
- Observed behavior
- Finding the mathematical difference between shifting schedules and fixed time slots without returning negative errors when times do not intersect.
Ensure that your time values are formatted correctly as standard time (e.g., hh:mm AM/PM) in your spreadsheet, and verify whether any of your scheduled shifts cross midnight, as overnight shifts require adjusted calculations.
Use MAX and MIN Functions for Same-Day Shifts
This method relies on the MAX and MIN formulas to isolate and calculate the exact overlapping time between a work shift and a time slot when both occur on the same day.
The combination of MAX and MIN functions elegantly determines the intersecting hours. By finding the minimum of the two end times and subtracting the maximum of the two start times, the formula accurately calculates the exact overlap duration.
Enter your shift start time in cell K2, shift end time in L2, time slot start time in M1, and time slot end time in M22.
Select an empty cell where you want the result to appear and input the formula: =MAX(0,MIN(L2,M22)-MAX(K2,M1)). The MAX(0, ...) wrapper ensures that if there is no overlap, the result defaults to zero instead of a negative number.
Select the result cell, right-click, and click on 'Format Cells'. In the Number tab, choose 'Time' or select 'Custom' and input 'h:mm' to display the result as standard hours.

Adjust Formula Logic for Shifts Crossing Midnight
Modify the basic calculation to account for work shifts or time slots that extend past midnight into the following day.
Calculate Shift Overlaps Easily in WPS Spreadsheet
WPS Spreadsheet fully supports advanced time calculation formulas like MAX and MIN, making it simple to manage FTE availability schedules and track overlapping work hours without compatibility issues.
- 1. Open WPS Spreadsheet: Launch WPS Office and open your employee schedule or time tracking workbook.
- 2. Input the Time Formula: Select the target cell and enter the =MAX(0,MIN(L2,M22)-MAX(K2,M1)) formula to calculate your time slot overlap.
- 3. Customize the Cell Format: Highlight your result cell, press Ctrl+1 to open the Format Cells dialog, and select your desired Time or Number format to display the hours.

Frequently Asked Questions
Why does my overlap formula return a #VALUE! error or negative number?
A #VALUE! error usually indicates that one or more cells are formatted as text rather than valid time formats. If you see a negative number without an error, it means the times do not overlap. Using the MAX(0, ...) wrapper in your formula forces negative overlap results to display as zero.
How do I convert the calculated overlapping time into decimal hours for payroll?
To convert a standard time format (such as 3:30) into decimal hours (3.5), multiply the entire result of your formula by 24. For example, use =(MAX(0,MIN(L2,M22)-MAX(K2,M1)))*24, and make sure the cell is formatted as a Number rather than Time.
Can I use this formula to check overlaps for multiple time slots at once?
The standard MAX and MIN formula calculates the overlap for one specific time slot at a time. To check across multiple varying slots, you must set up the formula in adjacent columns and use absolute references (like $K$2) for the shift times while keeping relative references for the specific time slots.




