Calculate Total Hours Worked in Excel Using 12-Hour Times
Question details
Calculate total employee hours from 12-hour shift start and end times.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- An employee timesheet contains multiple work periods, overnight shifts, days off, and leave codes.
- Observed behavior
- The desired total should include valid work intervals and display accumulated hours beyond 24.
Arrange each work period as a start-and-end pair, such as B5 and C5, and enter actual Excel time values with AM or PM. The formula below assumes each shift is shorter than 24 hours and treats blank or text-coded periods as zero hours.
Add Shift Intervals with an Overnight-Safe Formula
Use this formula for seven start-and-end pairs, including overnight shifts and periods marked with text leave codes.
In B5:O5, enter start and end times in pairs: B5/C5, D5/E5, F5/G5, H5/I5, J5/K5, L5/M5, and N5/O5. Include AM or PM when entering each time.
Select P5 and enter: =SUM(IF(AND(ISNUMBER(B5),ISNUMBER(C5)),MOD(C5-B5,1),0),IF(AND(ISNUMBER(D5),ISNUMBER(E5)),MOD(E5-D5,1),0),IF(AND(ISNUMBER(F5),ISNUMBER(G5)),MOD(G5-F5,1),0),IF(AND(ISNUMBER(H5),ISNUMBER(I5)),MOD(I5-H5,1),0),IF(AND(ISNUMBER(J5),ISNUMBER(K5)),MOD(K5-J5,1),0),IF(AND(ISNUMBER(L5),ISNUMBER(M5)),MOD(M5-L5,1),0),IF(AND(ISNUMBER(N5),ISNUMBER(O5)),MOD(O5-N5,1),0)).
Select P5, open Format Cells, choose Custom, and enter [h]:mm as the format. Copy the formula and formatting down for other employees if needed.

Calculate Employee Shift Hours in WPS Spreadsheets
Use WPS Spreadsheets to enter 12-hour shift times, calculate overnight intervals, and display the accumulated total in hours and minutes.
- 1. Open the timesheet: Open your workbook in WPS Spreadsheets and enter each start and end time with AM or PM in B5:O5, using adjacent pairs.
- 2. Enter the total formula: Select P5 and enter: =SUM(IF(AND(ISNUMBER(B5),ISNUMBER(C5)),MOD(C5-B5,1),0),IF(AND(ISNUMBER(D5),ISNUMBER(E5)),MOD(E5-D5,1),0),IF(AND(ISNUMBER(F5),ISNUMBER(G5)),MOD(G5-F5,1),0),IF(AND(ISNUMBER(H5),ISNUMBER(I5)),MOD(I5-H5,1),0),IF(AND(ISNUMBER(J5),ISNUMBER(K5)),MOD(K5-J5,1),0),IF(AND(ISNUMBER(L5),ISNUMBER(M5)),MOD(M5-L5,1),0),IF(AND(ISNUMBER(N5),ISNUMBER(O5)),MOD(O5-N5,1),0)).
- 3. Format the total: Select P5, open Format Cells, choose Custom, and enter [h]:mm to display accumulated hours.
- 4. Apply and save: Copy P5 down to other employee rows, check incomplete shifts and leave entries, and use File > Save to save the workbook.

Frequently Asked Questions
How does the formula handle an overnight shift?
MOD(end time-start time,1) rolls a negative difference into the next day. For example, 10:00 PM to 6:00 AM returns 8:00. Each shift must be shorter than 24 hours.
Why does my total reset after 24 hours?
A standard time format shows the time of day rather than accumulated hours. Select the total cell, open Format Cells > Custom, and use [h]:mm.
Can I put a leave code in a shift cell?
Yes. The formula treats a pair containing a text code or blank cell as zero worked hours. Add paid leave separately if it should count toward the total.
Why is a shift with a missing start or end time not counted?
The formula counts a period only when both cells contain numeric time values. Check the start-and-end pair and enter the missing time with AM or PM.




