Look Up Employee Shift Start and End Times Across Midnight in Excel
Question details
Find an employee's shift start and end times for a given event date and time, including overnight shifts.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A shift schedule contains employee names, shift dates, and start and end times. An event must be matched to the shift in progress.
- Observed behavior
- The lookup should return the shift whose start date-time is at or before the event and whose end date-time is after the event.
Check that shift dates and times are stored as Excel date and time values, not text. Confirm that the shift date represents the day the shift starts and that employee names match between the schedule and event data.
Match the Employee and Event Against Shift Date-Time Boundaries
Use calculated start and end date-times with FILTER to return the shift containing an event, even when the shift ends the next day.
This method includes the shift start but excludes the shift end. If shifts overlap for the same employee, FILTER returns every matching shift.
Select the schedule and choose Insert > Table. Name it ShiftTable in Table Design and include columns named Employee, ShiftDate, StartTime, and EndTime.
Add a StartDateTime column to ShiftTable and enter =[@ShiftDate]+[@StartTime]. Format the column to display both the date and time.
Add an EndDateTime column and enter =[@ShiftDate]+[@EndTime]+--([@EndTime]<[@StartTime]). An end time earlier than the start time is treated as occurring the next day.
Enter the employee name in a cell named EmployeeCell and the event date and time in a cell named EventDateTime. If the date and time are separate, add them together in the event date-time cell.
In an empty cell, enter =FILTER(ShiftTable[StartDateTime],(ShiftTable[Employee]=EmployeeCell)*(EventDateTime>=ShiftTable[StartDateTime])*(EventDateTime<ShiftTable[EndDateTime]),"No match"). In another cell, use the same formula but replace the first ShiftTable[StartDateTime] with ShiftTable[EndDateTime] to return the end.

Find Overnight Shifts in WPS Spreadsheets
Calculate shift date-time boundaries and use an INDEX and MATCH formula to find the first shift containing an employee's event.
- 1. Arrange the schedule: Open the workbook in WPS Spreadsheets. Put employee names in A, shift dates in B, start times in C, and end times in D, with schedule data in rows 2 through 100.
- 2. Calculate shift boundaries: Enter =B2+C2 in E2 and =B2+D2+--(D2<C2) in F2. Fill both formulas down through row 100 and format columns E and F to show date and time.
- 3. Enter the event: Enter the employee name in H2, the event date in I2, and the event time in J2. Make sure the date and time are recognized as spreadsheet values.
- 4. Look up the shift start: In an empty cell, enter =IFERROR(INDEX($E$2:$E$100,MATCH(1,INDEX(($A$2:$A$100=H2)*($E$2:$E$100<=I2+J2)*($F$2:$F$100>I2+J2),0),0)),"No match").
- 5. Look up the shift end: In another empty cell, enter =IFERROR(INDEX($F$2:$F$100,MATCH(1,INDEX(($A$2:$A$100=H2)*($E$2:$E$100<=I2+J2)*($F$2:$F$100>I2+J2),0),0)),"No match"). Format both results as date and time; the formulas return the first match if shifts overlap.

Frequently Asked Questions
Why does an event after midnight need the previous day's shift date?
An overnight shift starts on the previous date but ends on the event date. Comparing the full event date-time with calculated start and end date-times includes that shift without relying on the event date alone.
What happens if an event occurs exactly at the shift end time?
The formulas use a less-than comparison for the end, so an event exactly at the end is excluded from that shift. It can match a following shift that starts at that time.
Why does the lookup return No match?
Check that the employee name matches and that the event falls between the calculated boundaries. Also verify that the date and time cells contain date and time values rather than text.
Can the lookup return more than one shift?
The Excel FILTER formulas return all matching shifts if an employee has overlapping shifts. The WPS INDEX and MATCH formulas return the first matching row.




