Calculation Issues

How to Calculate an Employee's Total Hours on Their Last Workday in Excel

Kushani NimanthikaKushani Nimanthika Nov 10, 2026 868 views

Question details

The user needs a formula to calculate the exact duration between the first shift start time and the final shift end time on an employee's last recorded working day.

How to Calculate an Employee's Total Hours on Their Last Workday
Product
Spreadsheets
Device & OS
not provided
Scenario
Tracking employee work shifts where an employee might have multiple events in a day, or events crossing midnight, making it difficult to extract the exact total hours for their final day.
Observed behavior
Standard subtraction fails when shifts span across days or vary in event count per employee. A specialized formula is needed to identify the final workday and extract the minimum start time and maximum end time for that specific date.
Before you start

Ensure your dataset is sorted by Employee ID and then by Start Time. Verify that your Start and End columns contain valid Date and Time values, not just text.

Solution 1Recommended

Use an IF and MIN Array Formula (Recommended)

This formula identifies the final row for each employee and subtracts the earliest start time of their last day from the final end time.

This method assumes Column A contains the Employee ID, Column B contains the Start Date/Time, and Column C contains the End Date/Time. It extracts the date portion using the INT function to match all events occurring on that specific final day.

1
Select the target cell

Click on cell D2 (or the first cell in your blank duration column) to begin entering the formula.

2
Input the calculation formula

Type the following formula: =IF($A2=$A3,"",$C2-MIN(IF(($A$2:$A$18=$A2)*(INT($B$2:$B$18)=INT($B2)),$B$2:$B$18))) and press Enter.

3
Format the result as Time

Right-click cell D2, select 'Format Cells', navigate to the 'Number' tab, choose 'Time', and select a format that supports elapsed hours (like [h]:mm).

4
Fill the formula down

Click and drag the fill handle at the bottom right of cell D2 down through the rest of your data rows. The formula will only output a duration on the final row for each employee.

Use an IF and MIN Array Formula (Recommended)
Adjusting Ranges: Be sure to change $A$2:$A$18 and $B$2:$B$18 to match the actual row range of your dataset to ensure all employee data is calculated correctly.
Advanced Spreadsheet Capabilities

Calculate Complex Work Hours Easily with WPS Spreadsheet

WPS Spreadsheet fully supports advanced array formulas, date/time calculations, and dynamic array functions like UNIQUE, MAP, and LAMBDA. Handle complex timesheets and midnight-crossing shifts without any hassle.

  1. 1. Open your timesheet: Launch WPS Spreadsheet and open your employee hours document.
  2. 2. Apply the time formula: Paste the provided IF/MIN formula into your duration column.
  3. 3. Format and review: Apply the [h]:mm format from the Format Cells menu to instantly view total elapsed hours.
100% compatible with Microsoft Excel date and time formatting.Built-in support for advanced logic, IF arrays, and dynamic functions.User-friendly interface for managing large timesheet datasets easily.
microsoft office alternative - wps office

Frequently Asked Questions

How do I calculate total hours for a shift that crosses midnight?

If your cells contain both the Date and Time (e.g., 10/24/2023 10:00 PM to 10/25/2023 6:00 AM), standard subtraction (End - Start) works perfectly. If your cells only contain Time values, use the formula =MOD(End - Start, 1) to handle the midnight crossing without returning a negative error.

Why does my time formula return a decimal number instead of hours?

Spreadsheets store dates and times as serial numbers, where 1 equals a 24-hour day. A duration of 12 hours is stored as 0.5. To fix this, right-click the cell, choose 'Format Cells', and apply a Time format (such as h:mm).

How can I multiply calculated hours by an employee's hourly wage?

Because time is stored as a fraction of a day, multiplying formatted time directly by a wage rate will give an incorrect result. First, multiply the calculated time by 24 to convert it to decimal hours (e.g., 8:30 becomes 8.5), format that cell as a General number, and then multiply it by the hourly wage.

What does the INT function do in time calculations?

The INT function rounds down a number to the nearest integer. Since Date/Time values use integers for dates and decimals for time, using INT() removes the time portion, allowing you to isolate and compare just the specific calendar dates.