Working hours between two date/times excluding Lunch and weekends, diff time on Friday


Well-known Member
Oct 24, 2004
Office Version
  1. 2019
  1. Windows
I need some assistance with calculating working hours between two date/time cells. The working hours are 8:30 to 17:30 and the lunch break is 12:30 to 1:45

The date/time value could be outside the working hours but I only want to count the period within the working hours.

I have an existing formula (from Barry Houdini) that calculates the working hours minus the lunch breaks and excludes weekends and it works with date times outside the working hours.

The formula in cell M2 is:-
=(NETWORKDAYS(F2,G2,holiday)-1)*(EndTime-StartTime+StartLun-EndLun)+IF(NETWORKDAYS(G2,G2,holiday),MEDIAN(MOD(G2,1), EndTime,StartTime)-MEDIAN(MOD(G2,1), EndLun,StartLun),EndTime-EndLun)-IF(NETWORKDAYS(F2,F2,holiday),MEDIAN(MOD(F2,1), EndTime,StartTime)-MEDIAN(MOD(F2,1), EndLun,StartLun),StartTime-StartLun)

The date/time stamps are in cells:-
Start Date F2
End Date G2

I have Named Ranges for the date times and holidays used for the standard working week:-
Holiday (Range of 15 cells)

BUT … the working hours are fixed for Monday to Friday.
I would like to incorporate different working hours for Friday (8:30 to 15:00) with the same lunch break as Monday to Thursday. Is this possible?

Would anyone be able to assist in modifying the existing formula or perhaps come up with a different approach that would allow different working hours on a Friday?

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
col H
row 515/01/201908:3017:007.257.25
col I
working hours between17/01/2019row 33
and07/02/2019row 34

<colgroup><col><col><col span="5"><col><col><col span="6"></colgroup><tbody>
Upvote 0
Hi Oldbrewer,
Thank you for the reply, it looks like you have spent some time on this one.
Your formula accounts for different hours on a Friday but it does not account for lunch breaks or holidays. Also, it would (I think) require a very long list of dates from which to reference the formula.
Many thanks for the reply
Upvote 0
the lunch break is already built in, check the working hours each day.........sat and sun are also accounted employees holidays would need to be logged in another table and any "hours of holiday" would be deducted.......the dates them selves are generated from a formula - I could take it to 2020 in 5 seconds
Upvote 0
Thank you Oldbrewer,
I did not really grasp the full solution you offered, I think my brain must have been worn out as I spent the last few days looking for a work around to the problem. You are right, I could auto-generate the date list.

But there is still a problem, the cells containing the dates would be “date & time”.

So if the period I wanted to measure was quite short like:-
From [ 7/1/19 08:00] to [7/1/19 11:00] the formula would still deduct a lunch break for that period of time.

Your formula would work very well if the period of time crossed several whole days which included the lunch period.
I will keep playing with it and see if it can be adapted but I think this is a really difficult one to solve.
Upvote 0
Hi Oldbrewer,
Just to explain a little more, I’m trying to create a generic formula to handle working periods of time that would be better than the existing formula that I mentioned in the original post. The only flaw (that I can see) with the original formula is it cannot handle a shorter working day on a Friday.

The formula is used in a variety of workbooks for different uses, some workbooks measure absenteeism, and some measure holiday periods, some measure project working periods for KPI measurement and will probably be used for other projects in the future where time measurement is needed.
So I'm trying to imagine if someone is likely to log-off during a break time, probably not.

I will use your suggestions later today (RL is getting in the way at the moment) and see what I can come up with.
Many thanks
Upvote 0
Just for the sake of completeness and in case anyone else is looking for a similar solution. I have found an alternative approach. So I thought I would share it.

Basic solution is here (there is a downloadable spreadsheet available on the site)
The basic formula uses a range:- 0000111, seven numbers to represent the days of the week.
1= not active
0 = Active
So I have use three ranges
Range1 = Mon to Thursday (0000111)
Range2 = Fri (1111011)
Range3 = Lunch Break, Mon to Fri (0000011)

Each range is calculated in a separate column and then sum(Range1 + Range2 – Range3)
Holidays are in a separate named range and it works for date times within or outside of the working hours but only measures the time spent within the working hours.

Upvote 0

Forum statistics

Latest member

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