How to Calculate Working Hours Between Datetimes with Custom Weekends
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.
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.
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.
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.
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.
Multiply the total full working days by your standard daily working hours (e.g., 8 hours) to establish the baseline total hours.
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).
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 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. Open WPS Spreadsheet: Launch WPS Office and open your workbook containing the datetime data.
- 2. Enter the Formula: Select your target cell and input the NETWORKDAYS.INTL formula to calculate working days.
- 3. Define Custom Weekends: Specify your custom weekend string (e.g., '0000011') and select your holiday reference range.
- 4. Format the Result: Multiply the time result by 24 and change the cell format to Number to display the final hours accurately.

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.




