Calculate Night Penalty and Ordinary Shift Hours in Excel
Question details
Calculate paid ordinary and night penalty hours for shifts that cross midnight, excluding unpaid breaks.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A shift may overlap a night penalty window from 8:00 PM to 7:00 AM and include an unpaid break.
- Observed behavior
- The user needs paid hours divided between the night penalty window and ordinary hours.
Enter full dates and times for the shift and break, including the next day's date for an end time after midnight. This method assumes one unpaid break entirely within the shift; leave both break cells blank if there is no break.
Calculate overlap with each night penalty window
Use a date-by-date helper table to calculate penalty hours and subtract any unpaid break that falls within the window.
Each penalty window runs from 8:00 PM on its listed date to 7:00 AM the following day. The formulas return decimal hours.
The example uses rows 2 through 100 for penalty windows. If a shift spans more dates, extend the helper table and update the SUM range.
In Excel, enter the shift start in A2 and end in B2. Enter the unpaid break start in C2 and end in D2, or leave both blank. Include dates in all populated cells.
In E2, enter =IF(OR(A2="",B2=""),"",(B2-A2-IF(OR(C2="",D2=""),0,D2-C2))*24).
In F2, enter =IF(OR(A2="",B2=""),"",INT(A2)-1). In F3, enter =IF(F2="","",F2+1), then fill down until the list includes the date in B2. Format column F as a date.
In G2, enter =IF(F2="","",MAX(0,MIN($B$2,F2+1+TIME(7,0,0))-MAX($A$2,F2+TIME(20,0,0)))*24). In H2, enter =IF(OR(F2="",$C$2="",$D$2=""),0,MAX(0,MIN($D$2,F2+1+TIME(7,0,0))-MAX($C$2,F2+TIME(20,0,0)))*24). Fill both formulas down alongside the dates in column F.
In I2, enter =IF(F2="","",G2-H2) and fill it down alongside column F. In J2, enter =IF(OR(A2="",B2=""),"",SUM(I2:I100)) for penalty hours. In K2, enter =IF(E2="","",E2-J2) for ordinary hours. Format E and G:K as numbers.

Calculate night penalty hours in WPS Spreadsheets
Use the same date-aware helper table in WPS Spreadsheets to separate paid night penalty hours from ordinary hours and exclude an unpaid break.
- 1. Open a spreadsheet: In WPS Spreadsheets, open an XLSX workbook or create a new spreadsheet.
- 2. Enter shift details: Enter the full shift start and end dates and times in A2 and B2. Enter break start and end in C2 and D2, or leave both blank.
- 3. Calculate paid hours: Enter =IF(OR(A2="",B2=""),"",(B2-A2-IF(OR(C2="",D2=""),0,D2-C2))*24) in E2.
- 4. Build the penalty table: In F2:I2, enter the date, shift overlap, break overlap, and net penalty formulas from the solution above. Enter the F3 date formula and fill the helper formulas down through the shift end date.
- 5. Calculate the totals: Enter the J2 and K2 formulas from the solution above to display penalty and ordinary hours. Format the results as numbers, then use File > Save As to save the workbook.

Frequently Asked Questions
Why do I need to enter dates as well as times?
Dates tell Excel which day each time belongs to. Enter the actual next-day date for a shift or break ending after midnight so the subtraction and overlap calculations work correctly.
What if the unpaid break is outside the penalty window?
Enter the break start and end in C2 and D2. It is deducted from total paid hours, but the penalty-overlap formula deducts only the part that falls between 8:00 PM and 7:00 AM.
How do I handle a day with no shift?
Clear A2 through D2 for that shift. The paid, penalty, and ordinary totals will be blank when the shift start or end is missing.
Can I use this method for more than one unpaid break?
The formulas shown assume one break. For multiple breaks, calculate the duration and penalty-window overlap of each break separately, then subtract their totals from paid and penalty hours.




