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

#### jilianbenss

##### New Member
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...urs-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:
=(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))/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 from 5am Tuesday to 1am Wednesday).

The file looks like this, I'm trying to calculate in the column Working Hours
Tab 1:

 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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

#### jilianbenss

##### New Member
Thanks for the answer James.

#### James006

##### Well-known Member
Thanks for the answer James.

You are welcome ...

Hope this will help fixing your delicate problem ...:wink:

Replies
0
Views
50
Replies
1
Views
194
Replies
4
Views
392
Replies
3
Views
110
Replies
17
Views
958

1,129,698
Messages
5,637,879
Members
416,987
Latest member
XDee

### 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?

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