Calculate only working hours between two dates with several constraints (includes weekend, excludes holidays, working hours ranges different each day

Status
Not open for further replies.

jilianbenss

New Member
Joined
Aug 20, 2018
Messages
3
Hi all,



I have read many threads regarding the calculation of working hours between two dates, including the following thread
https://www.mrexcel.com/forum/excel-questions/426101-calculate-only-working-hours-between-two-dates-excluding-weekends.html and the great answers from member barry houdini and others (e.g. pedrowave). I am really grateful for the patience and quality of barry's and other members of this board.

I am facing a difficult calculation as there are many constraints.

I need to calculate the time elapsed between two tickets raised. A client raises a ticket, at any time and any day, and our staff resolves the ticket within our working hours.
I then need to calculate the time it takes to resolve the ticket within the working hours, including the weekend, and excluding bank holidays. If a ticket is resolved outside of working hours and days, only the time WITHIN the working hours and days should be counted.

I have found great answers that either include or exclude weekend. However, I have 3 major constraints that make all the formulas and solutions proposed in the mentioned thread unusable:




  • I manage several locations, each location has different working hours and different working days. E.g. NYC is open from Monday to Sunday, with different hours for each day. Los Angeles only Monday to Friday. New Orleans Monday to Saturday. Again, the working hours are different each day (e.g. Monday to Friday 5am 730pm, Saturday 6am - 2pm, Sunday 9am - 5pm).
  • Each location has different Bank Holidays because they're located in different states (and sometimes countries).
  • Some of our locations have working hours that finish late into the night (e.g. 5am to 1am).


    I know NETWORKDAYS cannot be used since it's a Mon-Fri formula, and I've tried to adapt barry houdini's formula #16 :


=(SUMPRODUCT(INT((WEEKDAY(A2-{2,3,4,5,6,7})+INT(B2)-INT(A2))/7),{9,9,9,9,9,4})-SUMPRODUCT((H$1:H$10>A2)*(H$1:H$10<b2),lookup(weekday(h$1:h$10),{1,7},{9,4}))+(mod(b2,1)-mod(a2,1))*24+if(weekday(a2)=7,8,7)-if(weekday(b2)=7,12,16)) span="" 24<=""></b2),lookup(weekday(h$1:h$10),{1,7},{9,4}))+(mod(b2,1)-mod(a2,1))*24+if(weekday(a2)=7,8,7)-if(weekday(b2)=7,12,16))>

<b2),lookup(weekday(h$1:h$10),{1,7},{9,4}))+(mod(b2,1)-mod(a2,1))*24+if(weekday(a2)=7,8,7)-if(weekday(b2)=7,12,16)) 24

A2 B2 being start date and finish date, H1:H10 being holidays.

However, this formula has fixed working hours, where I need to change the working hours for each day and each location. Also, I cannot seem to calculate properly working hours when they extend to the day after (e.g. office open from5am Tuesday to 1am Wednesday).



The file looks like this, I'm trying to calculate in the column Working Hours
Tab 1:</b2),lookup(weekday(h$1:h$10),{1,7},{9,4}))+(mod(b2,1)-mod(a2,1))*24+if(weekday(a2)=7,8,7)-if(weekday(b2)=7,12,16))>


Ticket number
Organization
Date Reported
Date of resolution
Working Hours

12583
Philadelphia

11/02/2017 16:59

13/02/2017 10:29

19029
NYC

8/11/2016 17:51

8/11/2016 20:31

12584
LA

11/02/2017 16:59

13/02/2017 10:29

12488
Kuala Lumpur

9/02/2017 19:59

10/02/2017 14:15

13284
Mumbai

24/02/2017 21:50

25/02/2017 9:27

19460
New Orleans

18/11/2016 11:54

19/11/2016 10:54

14784
Charlotteville

27/03/2017 0:00

27/03/2017 13:18

<tbody>
</tbody>


Tab 2 Working hours:
Monday Opening
Monday Closing
Tuesday Opening
Tuesday Closing
Wednesday Opening
Wednesday Closing
Thursday Opening
Thursday Closing
Friday Opening
Friday Closing
Saturday Opening
Saturday Closing
Sunday Opening
Sunday Closing
Business
NYC

5:00 AM

1:00 AM

5:00 AM

1:00 AM

5:00 AM

1:00 AM

5:00 AM

1:00 AM

5:00 AM

1:00 AM

5:00 AM

12:00 AM

2:00 PM

12:00 AM
Philadelphia

5:30 AM

7:00 PM

5:30 AM

7:00 PM

5:30 AM

7:00 PM

5:30 AM

7:00 PM

5:30 AM

7:00 PM

6:00 AM

2:00 PM

9:00 AM

5:00 PM
Charlotteville

5:00 AM

8:00 PM

5:00 AM

8:00 PM

5:00 AM

8:00 PM

5:00 AM

8:00 PM

5:00 AM

8:00 PM

5:00 AM

1:00 PM
N/A
N/A
New Orleans

5:00 AM

6:00 PM

5:00 AM

6:00 PM

5:00 AM

6:00 PM

5:00 AM

6:00 PM

5:00 AM

6:00 PM

4:00 AM

1:00 PM
N/A
N/A
LA

5:00 AM

6:00 PM

5:00 AM

6:00 PM

5:00 AM

6:00 PM

5:00 AM

6:00 PM

5:00 AM

6:00 PM
N/A
N/A
N/A
N/A
Kuala Lumpur

5:00 AM

6:00 PM

5:00 AM

6:00 PM

5:00 AM

6:00 PM

5:00 AM

6:00 PM

5:00 AM

6:00 PM
N/A
N/A
N/A
N/A
Mumbai

6:00 AM

9:00 AM

6:00 AM

9:00 AM

6:00 AM

9:00 AM

6:00 AM

9:00 AM

6:00 AM

9:00 AM
N/A
N/A
N/A
N/A

<tbody>
</tbody>


Tab 3 Bank holidays to exclude:

Philadelphia
NYC
Charlotteville
New Orleans
Kuala Lumpur
Mumbai
LA

1/01/2017

1/01/2016

1/01/2017

1/01/2016

1/01/2017

1/01/2016

1/01/2017

2/02/2017

26/01/2016

2/02/2017

26/01/2016

2/02/2017

26/01/2016

2/02/2017

26/01/2017

7/03/2016

26/01/2017

7/03/2016

26/01/2017

7/03/2016

26/01/2017

14/04/2017

25/03/2016

14/04/2017

25/03/2016

14/04/2017

25/03/2016

14/04/2017

15/04/2017

28/03/2016

15/04/2017

28/03/2016

15/04/2017

28/03/2016

15/04/2017

16/04/2017

25/04/2016

16/04/2017

25/04/2016

16/04/2017

25/04/2016

16/04/2017

17/04/2017

6/06/2016

17/04/2017

6/06/2016

17/04/2017

6/06/2016

17/04/2017

<tbody>
</tbody>


If anyone could help me I've been literally spending days on this.


Thanks

Cheers
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,471
Office Version
  1. 365
Platform
  1. Windows
Status
Not open for further replies.

Watch MrExcel Video

Forum statistics

Threads
1,129,323
Messages
5,635,596
Members
416,868
Latest member
andiwd

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
Top