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

Taul

Well-known Member
Joined
Oct 24, 2004
Messages
645
Office Version
2013, 2010
Platform
Windows
Hi,
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:-
Code:
=(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:-
StartTime
StartLun
EndLun
EndTime
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?
 

oldbrewer

Board Regular
Joined
Apr 11, 2010
Messages
10,985
col H
row 515/01/201908:3017:007.257.25
16/01/201908:3017:007.2514.5
17/01/201908:3017:007.2521.75
18/01/201908:3017:007.2529
19/01/201908:3015:005.2534.25
22/01/201908:3017:007.2541.5
23/01/201908:3017:007.2548.75
24/01/201908:3017:007.2556
25/01/201908:3017:007.2563.25
26/01/201908:3015:005.2568.5
29/01/201908:3017:007.2575.75
30/01/201908:3017:007.2583
31/01/201908:3017:007.2590.25
01/02/201908:3017:007.2597.5
02/02/201908:3015:005.25102.75
05/02/201908:3017:007.25110
06/02/201908:3017:007.25117.25
07/02/201908:3017:007.25124.5
08/02/201908:3017:007.25131.75
09/02/201908:3015:005.25137
col I
working hours between17/01/2019row 33
and07/02/2019row 34
110.00
formula
=OFFSET($H$4,MATCH($I$34,$H$5:$H$24,0),4)-OFFSET($H$4,MATCH($I$33,$H$5:$H$24,0)-1,4)

<colgroup><col><col><col span="5"><col><col><col span="6"></colgroup><tbody>
</tbody>
 

Taul

Well-known Member
Joined
Oct 24, 2004
Messages
645
Office Version
2013, 2010
Platform
Windows
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
Paul.
 

oldbrewer

Board Regular
Joined
Apr 11, 2010
Messages
10,985
the lunch break is already built in, check the working hours each day.........sat and sun are also accounted for....an 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
 

Taul

Well-known Member
Joined
Oct 24, 2004
Messages
645
Office Version
2013, 2010
Platform
Windows
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.
 

oldbrewer

Board Regular
Joined
Apr 11, 2010
Messages
10,985
and what if they clock off during the lunch break ?
 

Taul

Well-known Member
Joined
Oct 24, 2004
Messages
645
Office Version
2013, 2010
Platform
Windows
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
Paul.
 

Taul

Well-known Member
Joined
Oct 24, 2004
Messages
645
Office Version
2013, 2010
Platform
Windows
Hi,
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)
https://pedrowave.blogspot.com/2013/03/hours-between-dates.html
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.

Cheers
Paul.
 

Forum statistics

Threads
1,082,246
Messages
5,363,995
Members
400,772
Latest member
solbebe

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top