Counting working Hours in Specific Month between Two Date/times

Taul

Well-known Member
Joined
Oct 24, 2004
Messages
767
Office Version
  1. 2019
Platform
  1. Windows
Hi,
I looking for assistance to modify a formula from Barry Houdini (linked below). The linked formula provides basically what I'm looking for but I would like modify it in two ways:-
1. To show Working hours per month, rather than days.
2. To include Working start time (typically 08:30) and Working End time (typically 17:00), these time may be modified, so I would like them in a separate cell.

Start date & time in cell A2
End date & time in cell B2
Working Start time in cell A7 (08:30)
Working End time in cell B7 (17:00)
Holidays in range Z2:Z10
Formula in C2 and copied across to column N2 to cover the header months 1-Jan-23 to 1-Dec-23 (Rolling months/year in cells C1 to N1)

Is anyone able to assist in modifying the formula please, so far all my attempts have failed.
'=MAX(0,NETWORKDAYS.INTL(MAX(C$1,$A2),MIN(EOMONTH(C$1,0),$B2),"1000011",$Z$2:$Z$10))

You can amend that formula to only show working days based on your definition, so with the same setup, start date in A2, end date in B2 and the 1st of each month in C1 across, try this formula in C2, incorporating Caribeiro77's NETWORKDAYS.INTL suggestion, copied across and down if required

=MAX(0,NETWORKDAYS.INTL(MAX(C$1,$A2),MIN(EOMONTH(C$1,0),$B2),"1000011",$Z$2:$Z$10))

where Z2:Z10 contains your holiday dates, change as required
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
what weekday(s) are weekends? Sat/Sun, Fri/Sat, etc?, nevermind, i see it Mon, Sat, Sun.
 
Last edited:
Upvote 0
Okay, I think I have it figured out for you, try this:
Cell Formulas
RangeFormula
C1,Z2C1=DATE(2023,1,1)
D1:N1D1=EDATE(C1,1)
C2:N2C2= (--(($A2>=C$1)*($A2<EDATE(C$1,1))))* IF(INT($A2)=INT($B2),($B2-$A2),IF(MOD($A2,1)>MOD($A7,1),TIME(17,0,0)-MOD($A2,1),$B7-$A7))*24+ (--(($B2>=C$1)*($B2<EDATE(C$1,1))))* IF(INT($A2)=INT($B2),0,MIN(MOD($B2,1),MOD($B7,1))-MOD($A7,1))*24+ ((--($A2>=C$1)*($A2<EDATE(C$1,1)))+(--($B2>=C$1)*($B2<EDATE(C$1,1))))* (NETWORKDAYS.INTL(MAX(C$1,INT($A2+1)),MIN(EDATE(C$1,1),($B2-1)),"1000011",$Z$2:$Z$10)*8)
Z3Z3=DATE(2023,1,21)
Z4Z4=DATE(2023,2,17)
Z5Z5=DATE(2023,5,26)
Z6Z6=DATE(2023,7,4)
Z7Z7=DATE(2023,9,3)
Z8Z8=DATE(2023,10,12)
Z9Z9=DATE(2023,11,27)
Z10Z10=DATE(2023,12,25)
 
Upvote 0
Hi awoohaw,
Thank you so much for looking at this. I have tried your formula but there appears to be an issue if I have the start and end dates on the same day, it results in a negative number.
For example,
Start Date = Monday 24/Jan/2023 08:30
End Date = Monday 24/Jan/2023 17:00
This should result in 8.5 hrs (8:30) but it gives negative 39.5 hrs

I have moved the "work start" row down a little to make more room and changed the days range to only have sat & sun as the weekend ("0000011")

Book1
ABCDEFGHIJKLMNZ
1StartEnd01/01/202301/02/202301/03/202301/04/202301/05/202301/06/202301/07/202301/08/202301/09/202301/10/202301/11/202301/12/2023Holidays
2Sun 12/02/2023 12:00Wed 15/03/2023 16:00010187.500000000001/01/2023
3Thu 20/04/2023 08:00Thu 20/04/2023 17:00000-390000000021/01/2023
4Tue 24/01/2023 08:30Tue 24/01/2023 17:00-39.50000000000017/02/2023
5Tue 14/02/2023 08:30Wed 03/05/2023 17:00088.50024.5000000026/05/2023
604/07/2023
703/09/2023
812/10/2023
9Work StartWork Endduration (hr)27/11/2023
1008:3017:0008:3025/12/2023
Sheet1
Cell Formulas
RangeFormula
C1C1=DATE(2023,1,1)
D1:N1D1=EDATE(C1,1)
C2:N5C2= (--(($A2>=C$1)*($A2<EDATE(C$1,1))))* IF(INT($A2)=INT($B2),($B2-$A2),IF(MOD($A2,1)>MOD($A$10,1),TIME(17,0,0)-MOD($A2,1),$B$10-$A$10))*24+ (--(($B2>=C$1)*($B2<EDATE(C$1,1))))* IF(INT($A2)=INT($B2),0,MIN(MOD($B2,1),MOD($B$10,1))-MOD($A$10,1))*24+ ((--($A2>=C$1)*($A2<EDATE(C$1,1)))+(--($B2>=C$1)*($B2<EDATE(C$1,1))))* (NETWORKDAYS.INTL(MAX(C$1,INT($A2+1)),MIN(EDATE(C$1,1),($B2-1)),"0000011",$Z$2:$Z$10)*8)
C10C10=B10-A10
 
Upvote 0
I'm checking on it. that was one of the first things I worked on, but I seem to have subsequently deleted that part.
I also just realized, I multiplied the full days incorrectly. I'l fix that on my end as well.
 
Upvote 0
I also found another one of Barry Houdini's formula that provides most of what I'm looking for but it does not distribute the hours over each month.
I think it may need a combination of the original formula (using EOMONTH) and this one.

MrExcel.xlsx
ABCDEFGHIJKLMNOP
1StartEnd01/01/202301/02/202301/03/202301/04/202301/05/202301/06/202301/07/202301/08/202301/09/202301/10/202301/11/202301/12/2023Holidays
2Tue 14/02/2023 08:30Wed 03/05/2023 17:00476:0001/01/2023
3Tue 14/02/2023 08:30Tue 14/02/2023 17:008:3021/01/2023
417/02/2023
526/05/2023
604/07/2023
703/09/2023
812/10/2023
9Work StartWork Endduration (hr)27/11/2023
1008:3017:0008:3025/12/2023
11Start1EndT1HrsT1
Sheet2
Cell Formulas
RangeFormula
D1:N1D1=EDATE(C1,1)
C1C1=DATE(2023,1,1)
C2:C3C2=IF(A2>B2,0,+HrsT1*(NETWORKDAYS.INTL(A2,B2,"0000011",Holidays)-1)+IF(NETWORKDAYS.INTL(B2,B2,"0000011",Holidays)=0,MAX(Start1,EndT1),MAX(Start1,MIN(MOD(B2,1),EndT1)))-IF(NETWORKDAYS.INTL(A2,A2,"0000011",Holidays)=0,MIN(Start1,EndT1),MIN(EndT1,MAX(MOD(A2,1),Start1))))
C10C10=B10-A10
Named Ranges
NameRefers ToCells
EndT1=Sheet2!$B$10C10, C2:C3
Holidays=Sheet2!$P$2:$P$10C2:C3
HrsT1=Sheet2!$C$10C2:C3
Start1=Sheet2!$A$10C10, C2:C3
 
Upvote 0
Hey, I found a couple other errors i had also.

Try this:

Nope it had errors, I deleted.
 
Upvote 0
Thank you for looking at this. I think post #6 is the closest to capturing all that is needed, just need to figure out how the spread it over each month.
At the moment it captures the total time between the date/times.
 
Upvote 0
Thank you for looking at this. I think post #6 is the closest to capturing all that is needed, just need to figure out how the spread it over each month.
At the moment it captures the total time between the date/times.
i'm not giving up. I am taking this as a challenge to myself. I almost have it. stay tuned.
 
Upvote 0
@Taul
Okay, this is the best I have so far. It does have one flaw. If you start on a weekend or holiday it will add one extra day of hours (in this case 8.5). Although, it can be fixed with an edit check and subtracting I can't do that right now.

mr excel questions 20.xlsm
ABCDEFGHIJKLMNOP
1StartEnd2023-01-012023-02-012023-03-012023-04-012023-05-012023-06-012023-07-012023-08-012023-09-012023-10-012023-11-012023-12-01
2010000
3Sat 2023-02-25 08:45Tue 2023-02-28 13:000.0017.250.000.000.000.000.000.000.000.000.000.00
4Sun 2023-02-12 12:00Wed 2023-03-15 16:000.0097.5092.500.000.000.000.000.000.000.000.000.00
5Thu 2023-04-20 08:00Thu 2023-04-20 17:150.000.000.009.250.000.000.000.000.000.000.000.00
6Wed 2023-02-22 10:30Thu 2023-05-25 12:000.0035.50195.50170.00156.500.000.000.000.000.000.000.00
7Wed 2023-01-25 08:30Wed 2023-01-25 16:007.500.000.000.000.000.000.000.000.000.000.000.00
8
9
10WorkStartWorkEnd
1108:3017:00
128.5017.00
13
Taul
Cell Formulas
RangeFormula
D1D1=DATE(2023,1,1)
E1:O1E1=EDATE(D1,1)
D2:I2D2=((--(D$1<=$B3))*(--($A3<EDATE(D$1,1))))
D3:O7D3=((--(D$1<=$B3))*(--($A3<EDATE(D$1,1))))*( IF(MONTH($A3)=MONTH(D$1),MOD($B3,1)-MOD($A3,1),0)*24 + IF(INT($A3)=INT($B3),0,IF(MONTH($B3)=MONTH(D$1),MOD($B3,1)-MOD($A$11,1),0))*24 + MAX(0,NETWORKDAYS.INTL( IF(MONTH($A3)=MONTH(D$1),$A3+1,D$1), INT(IF(MONTH($B3)=MONTH(D$1),$B3,EDATE(D$1,1))-1), 1,$Q$3:$Q$11))* (24*(MOD($B$11,1)-MOD($A$11,1))) )
A12:B12A12=MOD(A11,1)*24
 
Upvote 0
Solution

Forum statistics

Threads
1,214,857
Messages
6,121,948
Members
449,056
Latest member
FreeCricketId

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