Calculation Issues

How to Calculate Working Hours Between Datetimes with Custom Weekends

Aamir Naveed AkramAamir Naveed Akram Nov 11, 2026 869 views

Question details

The user needs to calculate the exact number of working hours between two datetime stamps, taking into account custom weekend patterns, holidays, and rules for partial or overnight days.

Product
Spreadsheet
Device & OS
not provided
Scenario
Calculating employee working hours, project durations, or SLA resolution times based on specific business hours.
Observed behavior
Standard date difference formulas return total elapsed hours, failing to exclude non-working hours, custom weekends, and designated holidays.
Before you start

Ensure you have your start and end datetimes in separate cells, your daily business hours defined (e.g., 9:00 AM to 5:00 PM), and a designated cell range listing your holiday dates.

Solution 1Recommended

Use NETWORKDAYS.INTL for Custom Working Hours Calculation

Utilize the NETWORKDAYS.INTL function to exclude custom weekends and holidays, combined with time extraction to handle partial working hours on the start and end days.

Calculating exact working hours requires breaking the datetime down into full working days and partial hours. The NETWORKDAYS.INTL function is perfect for finding the number of full days while respecting custom weekend schedules.

1
Separate Dates and Times

If your data is in a single datetime format (e.g., cell A2), use =INT(A2) to extract the date and =MOD(A2,1) to extract the time for both your start and end timestamps.

2
Calculate Full Working Days

Use the formula =NETWORKDAYS.INTL(Start_Date, End_Date, Weekend_Code, Holidays_Range) to get the total working days. For example, use '0000011' as the Weekend_Code to set Saturday and Sunday as weekends.

3
Adjust for Daily Working Hours

Multiply the total full working days by your standard daily working hours (e.g., 8 hours) to establish the baseline total hours.

4
Account for Partial Days

Subtract the non-working hours from the first and last day. Use the MAX and MIN functions to ensure the start and end times fall within your specified business hours (e.g., 9:00 AM to 5:00 PM).

5
Format the Output

Spreadsheets store time as fractions of a day. Multiply your final time result by 24, right-click the cell, select 'Format Cells', and apply a 'Number' format to display the total elapsed hours.

Use NETWORKDAYS.INTL for Custom Working Hours Calculation
Custom Weekend Codes: The weekend string in NETWORKDAYS.INTL is 7 characters long, representing Monday through Sunday. A '0' means a workday, and a '1' means a weekend. For example, '0101010' makes Tuesday, Thursday, and Saturday weekend days.
Advanced Time Calculations in WPS

Use WPS Spreadsheet for Complex Date and Time Calculations

WPS Spreadsheet features a comprehensive library of date and time functions, including NETWORKDAYS.INTL. It empowers you to effortlessly track working hours, manage project timelines, and calculate SLAs with precise custom parameters.

  1. 1. Open WPS Spreadsheet: Launch WPS Office and open your workbook containing the datetime data.
  2. 2. Enter the Formula: Select your target cell and input the NETWORKDAYS.INTL formula to calculate working days.
  3. 3. Define Custom Weekends: Specify your custom weekend string (e.g., '0000011') and select your holiday reference range.
  4. 4. Format the Result: Multiply the time result by 24 and change the cell format to Number to display the final hours accurately.
Fully compatible with Microsoft Excel formulas and date/time functionsEasily configure custom weekend parameters and holiday exclusionsFree, lightweight, and easy to use for data analysisFamiliar user interface ensuring seamless migration from other office suites
microsoft office alternative - wps office

Frequently Asked Questions

How do I specify custom weekend days in the formula?

In NETWORKDAYS.INTL, use the weekend string parameter as the third argument. It is a 7-character string where '1' represents a non-working day and '0' represents a workday, starting from Monday. For example, '0000011' denotes Saturday and Sunday as weekends.

Why is my calculation result showing as a date instead of total hours?

Spreadsheets store time as fractions of a 24-hour day. If you are calculating total hours, you must multiply your final result by 24. Then, change the cell's formatting from Date/Time to a General or Number format.

Can I exclude specific public holidays from the working hours calculation?

Yes, you can provide a range of cells containing your specific holiday dates as the fourth argument in the NETWORKDAYS.INTL function. The formula will automatically deduct these dates from the total working day count.

How do I handle overnight shifts when calculating working hours?

For overnight shifts (e.g., 10 PM to 6 AM), standard time subtraction will yield a negative number. You can handle this by using the MOD function. For example, =MOD(End_Time - Start_Time, 1) will correctly return the elapsed hours across midnight.