Add a specified number of working hours to a date & time, given working day start, end and break times and holidays

AquaBuoy

New Member
Joined
Mar 3, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi, I’m looking for a formula that provides a more granular version of Excel’s WORKDAY function. It needs to add a decimal number of working hours to a date and time value, accounting for an 08:00 to 17:00 workday (Monday to Friday), with a lunch break from 13:00 to 14:00 each day (those times need to be configurable), and a list of holidays to produce a due date and time.

So, given these working hours (Monday to Friday) and list of Holidays (J2:J3):
WorkHours_Calculations.xlsx
GHIJ
1Working Times (Mon to Fri)Holidays
2WorkDay_Start 08:0006 March 2024
3LunchBreak_Start13:0001 May 2024
4LunchBreak_End14:00
5WorkDay_End17:00
6Work_Hrs_per_Day8
Sheet1
Cell Formulas
RangeFormula
H6H6=((LunchBreak_Start-WorkDay_Start)+(WorkDay_End-LunchBreak_End))*24
Named Ranges
NameRefers ToCells
LunchBreak_End=Sheet1!$H$4H6
LunchBreak_Start=Sheet1!$H$3H6
WorkDay_End=Sheet1!$H$5H6
WorkDay_Start=Sheet1!$H$2H6

The formula needs to replicate the manually calculated values in the Due Date & Time column (C).
WorkHours_Calculations.xlsx
ABC
1Start Date & Time# HoursDue Date & Time
2Mon, 04 Mar 2024 08:001.25Mon, 04 Mar 2024 09:15
3Mon, 04 Mar 2024 11:003.00Mon, 04 Mar 2024 15:00
4Mon, 04 Mar 2024 15:034.00Tue, 05 Mar 2024 10:03
5Mon, 04 Mar 2024 10:0012.00Tue, 05 Mar 2024 15:00
6Mon, 04 Mar 2024 16:008.00Tue, 05 Mar 2024 16:00
7Tue, 05 Mar 2024 07:302.50Tue, 05 Mar 2024 10:30
8Tue, 05 Mar 2024 13:302.50Tue, 05 Mar 2024 16:30
9Tue, 05 Mar 2024 15:004.00Thu, 07 Mar 2024 10:00
10Tue, 05 Mar 2024 18:008.00Thu, 07 Mar 2024 17:00
11Fri, 08 Mar 2024 12:0032.00Thu, 14 Mar 2024 12:00
Sheet1


Any help is greatly appreciated.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
The following (monstrous) formula returns the expected results for the posted dataset:
Excel Formula:
=LET(aaa,MOD(A2,1),bbb,MOD(B2,$H$6)/24,ddd,WORKDAY(A2,INT(B2/$H$6),$J$2:$J$11)+bbb+MAX(IF(aaa<=LunchBreak_Start,WorkDay_Start,LunchBreak_End),MIN(aaa,WorkDay_End))+(MOD(LunchBreak_Start-aaa,1)<bbb)*(LunchBreak_End-LunchBreak_Start)+(MOD(WorkDay_End-aaa,1)<bbb)*MOD(WorkDay_Start-WorkDay_End,1),WORKDAY(ddd-1,1,$J$2:$J$11)+MOD(ddd,1))
 
Upvote 0
The following (monstrous) formula returns the expected results for the posted dataset:
Excel Formula:
=LET(aaa,MOD(A2,1),bbb,MOD(B2,$H$6)/24,ddd,WORKDAY(A2,INT(B2/$H$6),$J$2:$J$11)+bbb+MAX(IF(aaa<=LunchBreak_Start,WorkDay_Start,LunchBreak_End),MIN(aaa,WorkDay_End))+(MOD(LunchBreak_Start-aaa,1)<bbb)*(LunchBreak_End-LunchBreak_Start)+(MOD(WorkDay_End-aaa,1)<bbb)*MOD(WorkDay_Start-WorkDay_End,1),WORKDAY(ddd-1,1,$J$2:$J$11)+MOD(ddd,1))
Thanks ever so much Tetra201. This is a huge help. I noticed two problems:
1. My expected result for row 11 (32 hours added to 8 Mar 2024 12:00) above was incorrect. I hadn't accounted for the holiday. My apologies.
2. The formula doesn't appear to be accurate when the start date & time is outside of business hours, on a holiday or on a weekend.
Could I impose on you to have another go at it to get all the Calculated dates & times in column D to match the Expected values in column C?

WorkHours_Calculations.xlsx
ABCDEFGHI
1Start Date & Time# HoursExpected Due Date & TimeCalculated Due Date & TimeWorking Hours (Monday to Friday)Holidays_List
2Mon, 04 Mar 2024 08:001.25Mon, 04 Mar 2024 09:15Mon, 04 Mar 2024 09:15WorkDay_Start 8:00:00 AMWed, 06 Mar 2024
3Mon, 04 Mar 2024 11:003.00Mon, 04 Mar 2024 15:00Mon, 04 Mar 2024 15:00LunchBreak_Start1:00:00 PMWed, 01 May 2024
4Mon, 04 Mar 2024 15:034.00Tue, 05 Mar 2024 10:03Tue, 05 Mar 2024 10:03LunchBreak_End2:00:00 PM
5Mon, 04 Mar 2024 10:0012.00Tue, 05 Mar 2024 15:00Tue, 05 Mar 2024 15:00WorkDay_End5:00:00 PM
6Mon, 04 Mar 2024 16:008.00Tue, 05 Mar 2024 16:00Tue, 05 Mar 2024 16:00Work_Hrs_per_Day8
7Tue, 05 Mar 2024 07:302.50Tue, 05 Mar 2024 10:30Tue, 05 Mar 2024 10:30
8Tue, 05 Mar 2024 13:302.50Tue, 05 Mar 2024 16:30Tue, 05 Mar 2024 16:30
9Tue, 05 Mar 2024 15:004.00Thu, 07 Mar 2024 10:00Thu, 07 Mar 2024 10:00
10Tue, 05 Mar 2024 18:008.00Thu, 07 Mar 2024 17:00Thu, 07 Mar 2024 17:00
11Fri, 08 Mar 2024 12:0032.00Thu, 14 Mar 2024 12:00Fri, 15 Mar 2024 12:00
12Mon, 04 Mar 2024 18:002.00Tue, 05 Mar 2024 10:00Mon, 04 Mar 2024 19:00
13Wed, 06 Mar 2024 08:304.00Thu, 07 Mar 2024 12:00Thu, 07 Mar 2024 12:30
14Wed, 06 Mar 2024 11:304.25Thu, 07 Mar 2024 12:15Thu, 07 Mar 2024 16:45
15Wed, 06 Mar 2024 12:305.00Thu, 07 Mar 2024 13:00Thu, 07 Mar 2024 09:30
16Wed, 06 Mar 2024 13:305.50Thu, 07 Mar 2024 14:30Thu, 07 Mar 2024 10:30
17Wed, 06 Mar 2024 14:307.50Thu, 07 Mar 2024 16:30Thu, 07 Mar 2024 13:00
18Wed, 06 Mar 2024 15:309.00Fri, 08 Mar 2024 09:00Thu, 07 Mar 2024 16:30
19Sat, 09 Mar 2024 11:002.00Mon, 11 Mar 2024 10:00Mon, 11 Mar 2024 13:00
20Sun, 10 Mar 2024 18:003.00Mon, 11 Mar 2024 11:00Mon, 11 Mar 2024 20:00
Sheet1
Cell Formulas
RangeFormula
G6G6=((LunchBreak_Start-WorkDay_Start)+(WorkDay_End-LunchBreak_End))*24
D2:D20D2=LET(aaa,MOD(A2,1),bbb,MOD(B2,Work_Hrs_per_Day)/24,ddd,WORKDAY(A2,INT(B2/Work_Hrs_per_Day),Holidays_List)+bbb+MAX(IF(aaa<=LunchBreak_Start,WorkDay_Start,LunchBreak_End),MIN(aaa,WorkDay_End))+(MOD(LunchBreak_Start-aaa,1)<bbb)*(LunchBreak_End-LunchBreak_Start)+(MOD(WorkDay_End-aaa,1)<bbb)*MOD(WorkDay_Start-WorkDay_End,1),WORKDAY(ddd-1,1,Holidays_List)+MOD(ddd,1))
Named Ranges
NameRefers ToCells
Holidays_List=Sheet1!$I$2:$I$3D2:D20
LunchBreak_End=Sheet1!$G$4G6, D2:D20
LunchBreak_Start=Sheet1!$G$3G6, D2:D20
Work_Hrs_per_Day=Sheet1!$G$6D2:D20
WorkDay_End=Sheet1!$G$5G6, D2:D20
WorkDay_Start=Sheet1!$G$2G6, D2:D20
 
Upvote 0

Forum statistics

Threads
1,223,868
Messages
6,175,082
Members
452,611
Latest member
bls2024

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