Formula for calculating business hours between 2 date/times

JenkinsM82

New Member
Joined
May 17, 2018
Messages
9
I'm trying to create a formula that will calculate the number of business hours between two date/times. The start of business hours is 8:00 am and the end is 5:00 pm. Plus, I need to take holidays into consideration. In these examples, 1/2/2023 is in the "Holidays" list.

ExampleStart Time (A1)End Time (B1)# of Hours
A1/4/2023 1:30:00 PM1/6/2023 3:30:00 PM20.00
B1/2/2023 5:06:00 AM1/3/2023 9:00:00 AM1.00
C1/2/2023 9:18:00 AM1/3/2023 8:19:00 AM0.32
D1/3/2023 10:00:00 AM1/4/2023 9:00:00 AM8.00
Here is the formula I'm using:

=(NETWORKDAYS.INTL(A1, B1, "0000000", Holidays)-1) * 9 + MAX(MIN(MOD(B1,1), TIMEVALUE("17:00")) - MAX(MOD(A1,1), TIMEVALUE("08:00")), 0) * 24

This formula works for examples A and B but example C results in 0 and example D results in 9.

Anyone have any ideas on how to fix this?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I'm trying to create a formula that will calculate the number of business hours between two date/times. The start of business hours is 8:00 am and the end is 5:00 pm. Plus, I need to take holidays into consideration. In these examples, 1/2/2023 is in the "Holidays" list.

ExampleStart Time (A1)End Time (B1)# of Hours
A1/4/2023 1:30:00 PM1/6/2023 3:30:00 PM20.00
B1/2/2023 5:06:00 AM1/3/2023 9:00:00 AM1.00
C1/2/2023 9:18:00 AM1/3/2023 8:19:00 AM0.32
D1/3/2023 10:00:00 AM1/4/2023 9:00:00 AM8.00
Here is the formula I'm using:

=(NETWORKDAYS.INTL(A1, B1, "0000000", Holidays)-1) * 9 + MAX(MIN(MOD(B1,1), TIMEVALUE("17:00")) - MAX(MOD(A1,1), TIMEVALUE("08:00")), 0) * 24

This formula works for examples A and B but example C results in 0 and example D results in 9.

Anyone have any ideas on how to fix this?
Try it, after you defined the holidays in a range:
Book1
ABCD
1Start Time End TimeHolidaysHours / minutes
21/4/2023 13:301/6/2023 15:3020:00
31/2/2023 5:061/3/2023 9:001/2/20231:00
41/2/2023 9:181/3/2023 8:190:19
51/3/2023 10:001/4/2023 9:008:00
Sheet1
Cell Formulas
RangeFormula
D2:D5D2=(NETWORKDAYS.INTL(A2,B2,11,C$2:C$5)-1)*("17:00"-"8:00")+IF(NETWORKDAYS.INTL(B2,B2,11,C$2:C$5),MEDIAN(MOD(B2,1),"8:00","17:00"),"17:00")-MEDIAN(NETWORKDAYS.INTL(A2,A2,11,C$2:C$5)*MOD(A2,1),"8:00","17:00")
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,596
Members
452,657
Latest member
giadungthienduyen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top