Calculation Issues

Calculate Overnight Hours Between Midnight and 6 AM in Excel

Huda QurayshiHuda Qurayshi Nov 11, 2026 868 views

Question details

The user needs to calculate the specific portion of a timesheet shift that was worked overnight between midnight and 6:00 AM.

How to Calculate Overnight Hours Between Midnight and 6 AM in Excel
Product
Excel
Device & OS
not provided
Scenario
Tracking employee shifts on a timesheet and isolating the total hours worked during a specific overnight window (12:00 AM to 6:00 AM).
Observed behavior
Users need to extract accurate time durations from date/time cells using mathematical formulas rather than formatting the values as text, which breaks downstream calculations.
Before you start

Ensure that your start and end times are recorded as standard Excel Date/Time serial numbers (e.g., '10/24/2023 22:00') rather than plain text, so mathematical formulas can process them properly.

Solution 1Recommended

Use MIN and MAX Formulas for Shifts Up to 18 Hours

This is the most reliable method for standard work shifts. It uses mathematical logic to extract the time portion falling strictly between 0:00 (midnight) and 6:00 AM (0.25 as a daily fraction).

Avoid using the TEXT function to calculate durations, as it converts numeric time values into text strings that cannot be summed later. Instead, rely on mathematical extraction.

In Excel, times are stored as fractions of a day. Therefore, 6:00 AM is exactly 0.25 (6 divided by 24).

1
Extract the exact date and time (Optional)

If you need to separate your date and time for visual reference, use =INT(H2) to get the whole date, and =MOD(H2,1) to extract just the fractional time.

2
Input the overnight calculation formula

Assuming your Start Time is in cell H2 and your End Time is in cell I2, click the cell where you want the overnight hours displayed and enter: =MAX(MIN(MOD(I2,1),0.25)-MOD(H2,1)*(INT(H2)=INT(I2)),0)

3
Format the result as elapsed time

Right-click the result cell, select 'Format Cells', navigate to the 'Custom' category, and type [h]:mm into the Type box. This ensures durations display correctly even if they exceed 24 hours.

Use MIN and MAX Formulas for Shifts Up to 18 Hours
Formula Breakdown: This formula uses MOD(I2,1) to look at the end time, limits the calculation ceiling to 6:00 AM using MIN(..., 0.25), and ensures negative times aren't returned using the MAX(..., 0) wrapper.
Track Timesheets Easily with WPS Spreadsheet

Use WPS Spreadsheet for Advanced Time Calculations

WPS Spreadsheet fully supports Excel's complex time calculation formulas, including INT, MOD, and advanced logical arrays. It provides a lightweight, highly compatible environment to handle your timesheet data efficiently.

  1. 1. Open your timesheet: Launch WPS Spreadsheet and open your existing timesheet document.
  2. 2. Verify date/time formats: Select your Start and End columns, right-click to choose 'Format Cells', and ensure they are set to a Date/Time format rather than Text.
  3. 3. Apply the calculation formula: Enter the formula =MAX(MIN(MOD(I2,1),0.25)-MOD(H2,1)*(INT(H2)=INT(I2)),0) exactly as you would in Excel to calculate the midnight to 6 AM window.
  4. 4. Format elapsed time: Press Ctrl+1 to open the format menu, choose 'Custom', and input [h]:mm to correctly display the calculated durations.
100% compatible with Microsoft Excel formulas, cell formatting, and timesheet templates.Free, comprehensive alternative to Microsoft Office.Lightweight software that loads quickly even with thousands of calculation rows.Familiar ribbon interface ensures zero learning curve when migrating from Excel.
microsoft office alternative - wps office

Frequently Asked Questions

Why shouldn't I use the TEXT function to calculate time differences?

The TEXT function converts numeric date and time values into text strings. While it might look correct visually (e.g., '04:00'), a text string cannot be processed by mathematical formulas like SUM. If you try to add up a week's worth of text-based hours, you will get an error or a result of zero.

What does the [h]:mm custom format do?

In spreadsheet software, standard 'h:mm' formatting resets to zero once it hits 24 hours. Placing square brackets around the 'h' ([h]:mm) tells the program to display total elapsed hours, allowing you to correctly show totals like '32:15' for a 32-hour work week.

Why is the MOD function used for time calculations?

Dates and times are stored as serial numbers where whole numbers represent days and decimals represent time (e.g., 0.5 is 12:00 PM). Using =MOD(cell, 1) divides the serial number by 1 and returns only the remainder, effectively stripping away the date and leaving only the pure time value for calculation.

Why is 6:00 AM represented as 0.25 in the formula?

Because time is calculated as a fraction of a 24-hour day. 6 divided by 24 equals 0.25. Similarly, 12:00 PM (noon) is 0.5, and 6:00 PM is 0.75.