# Counting Business hours between two dates

#### Kommerce

##### New Member
Hi Guys!

As the title says, I'm basically looking to calculate the difference in hours between two date/time fields in this format DD/MM/YY HH:MM. When calculating the difference, I only want to calculate BUSINESS HOURS between the two dates and omit weekends from the calculation.

As an example:
A1=05/09/2014 08:00.......... A2=08/09/2014 18:00
Therefore by running this VBA code or whatnot, the output should spit out the value "20:00:00". This is because it counts the hours on the 05th which is a friday from 08:00 to 18:00 which is 10 hours and skips the weekend but counts the 08th which is a Monday from 08:00AM to 18:00 which is an additional 10 hours.
Therefore 10+10=20

I have tried using a custom add in I found but it doesn't seem to work.
Is there a potential VBA/macro solution?
Any help would be greatly appreciated. Whoever can solve this is an absolute legend.

### Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
For what it's worth guys. I've worked it out.

This is the solution for anyone interested.

L12 = Start date and time
M12 = End date and time
F11 = start of working day eg. 08:00
F12 = end of working day e.g 18:00
B2:B37 = Dates of Public Holidays DD/MM/YYYY format

=IF(NETWORKDAYS(L12,M12,B2:B37)=1,(MIN(\$F\$12,MOD(M12,1))-MAX(\$F\$11,MOD(L12,1))),(NETWORKDAYS(L12,M12,B2:B37)-2)*(600/1440)+(\$F\$12-MAX(MOD(L12,1),\$F\$11))+MIN(MOD(M12,1),\$F\$12)-\$F\$11)

Unfortunately, I have to bring this back up. For some reason even though this gives a close figure to what the actual difference is, it doesn't give an exact. For e.g.

If people tried the difference between 05/08/2014 19:45 and 06/08/2014 09:47 the output should be 0:01:47 but instead it's giving 0:02:19.

Does anyone know why this may be or another accurate way to work out what I need as accurately as possible?

Try this version

=(NETWORKDAYS(L12,M12,B\$2:B\$37)-1)*(F\$12-F\$11)+IF(NETWORKDAYS(M12,M12,B\$2:B\$37),MEDIAN(MOD(M12,1),F\$11,F\$12),F\$12)-MEDIAN(NETWORKDAYS(L12,L12,B\$2:B\$37)*MOD(L12,1),F\$12,F\$11)

Last edited:
Try this version

=(NETWORKDAYS(L12,M12,B\$2:B\$37)-1)*(F\$12-F\$11)+IF(NETWORKDAYS(M12,M12,B\$2:B\$37),MEDIAN(MOD(M12,1),F\$11,F\$12),F\$12)-MEDIAN(NETWORKDAYS(L12,L12,B\$2:B\$37)*MOD(L12,1),F\$12,F\$11)

Mate, you are a legend. Apologies for the late reply but that actually calculates it to an exact amount.

THANKYOU!

Replies
4
Views
782
Replies
1
Views
373
Replies
1
Views
293
Replies
5
Views
607
Replies
5
Views
100

1,219,998
Messages
6,151,378
Members
451,023
Latest member
dwalc

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

### Which adblocker are you using?

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

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