Counting Business hours between two dates

Kommerce

New Member
Joined
Jun 25, 2014
Messages
27
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.
Thanks in advance!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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)
 
Upvote 0
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?
 
Upvote 0
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:
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,037
Members
448,543
Latest member
MartinLarkin

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