Calculate total hours from two entries, with in work hours, skipping weekends.

camthekitchenguy

New Member
Joined
Apr 20, 2022
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Recently found this forum after googling for different how-to's.
Came across different tutorials that were a little over my head which includes NetworkDays.

I am trying to have 2 date entries with time and date formatted like below, that will add together the hours worked within a working hours range of 7am till 3:30pm, skipping weekends.
4/18/22 7:00 AM
4/20/22 3:30 PM

I have come across other threads that are solving similar problems but was unable to adapt it properly
Any help, or direction to the correct thread, is appreciated.
Thanks
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Production Tracking.xlsx
IJKLMNOPQRS
1Production
2SawCNCEdgebandDowlingPickingDoors + Drawer BoxAssemblyParts WrappedRecutsCompleteDays
3
4
5
20
21
22
23
24
254/18/22 7:00 AM4/18/22 7:00 AM4/18/22 7:00 AM4/18/22 8:30 AM4/19/22 7:00 AM4/20/22 7:30 AM4/19/22 2:15 AM
264/19/22 3:30 PM4/19/22 12:30 PM4/20/22 3:30 PM4/20/22 3:30 PM4/20/22 3:30 PM4/20/22 3:30 PM
27
Production 2022
 
Upvote 0
I put the formula in row 27. Below that is the thing broken up a bit so it might be easier to understand.
MrExcelPlayground8.xlsx
HIJKLMNOPQRS
1Production
2SawCNCEdgebandDowlingPickingDoors + Drawer BoxAssemblyParts WrappedRecutsCompleteDays
3
4
5
20
21
22
23
24Workday
257:00:00 AMMon 4/18/22 7:00 AMMon 4/18/22 7:00 AMMon 4/18/22 7:00 AMMon 4/18/22 8:30 AMTue 4/19/22 7:00 AMWed 4/20/22 7:30 AMTue 4/19/22 2:15 AM
263:30:00 PMTue 4/19/22 3:30 PMTue 4/19/22 12:30 PMWed 4/20/22 3:30 PMWed 4/20/22 3:30 PMWed 4/20/22 3:30 PMTue 4/26/22 12:30 PMTue 4/19/22 3:15 PM
2717.0014.0025.5024.0017.0039.008.25
28171725.525.51742.58.5
290.000.000.001.500.000.500.00
300.003.000.000.000.003.000.25
3117.0014.0025.5024.0017.0039.008.25
Sheet9
Cell Formulas
RangeFormula
I27:O27I27=NETWORKDAYS(I25,I26)*($H$26-$H$25)*24-MAX(MOD(I25,1)-$H$25,0)*24-MAX($H$26-MOD(I26,1),0)*24
I28:O28I28=NETWORKDAYS(I25,I26)*($H$26-$H$25)*24
I29:O29I29=MAX(MOD(I25,1)-$H$25,0)*24
I30:O30I30=MAX($H$26-MOD(I26,1),0)*24
I31:O31I31=I28-I29-I30
 
Upvote 0
N4=Start Day & Time
O4=End Day & Time
S3=7:00:00
Z3=15:30:00


Excel Formula:
=IF(AND($N4>0,$O4>0),IF(INT($N4)-INT($O4)=0,MAX(0,MIN($Z$3,ROUND(MOD($O4,1),6))-MAX($S$3,ROUND(MOD($N4,1),6))),MAX(0,MIN($Z$3,ROUND(MOD($O4,1),6))-$S$3)+($Z$3-MAX(0,MAX($S$3,ROUND(MOD($N4,1),6))))+(INT($O4)-INT($N4)>1)*($Z$3-$S$3)*NETWORKDAYS(INT($N4)+1,INT($O4)-1)),IF(INT($N4)-INT(NOW())=0,MAX(0,MIN($Z$3,ROUND(MOD(NOW(),1),6))-MAX($S$3,ROUND(MOD($N4,1),6))),MAX(0,MIN($Z$3,ROUND(MOD(NOW(),1),6))-$S$3)+($Z$3-MAX(0,MAX($S$3,ROUND(MOD($N4,1),6))))+(INT(NOW())-INT($N4)>1)*($Z$3-$S$3)*NETWORKDAYS(INT($N4)+1,INT(NOW())-1)))
 
Upvote 0
I'm realizing I didn't think about omitting 30min a day for unpaid lunch. I could just adjust the end time by 30min to account; which I am prepared to do.

Is there a way to deduct 30min per day within the range to account for this? If that's possible can the time in the day be determined so that it is taken into account based on the calculation when referencing the start & end time? For example, removing 11:30am to 12:00mm?
 
Upvote 0
Person shift working Hrs: Start=N4, End= O4
Working Hrs: Start=S3 (7:00), End= T3(15:30)
Break Hrs: Start=V3(11:30), End=W3(12:00)

Excel Formula:
=IF(AND($N4>0,$O4>0),IF(INT($N4)-INT($O4)=0,(WEEKDAY($N4,2)<6)*(MAX(0,MIN($V$3,MOD($O4,1))-MAX(MOD($N4,1),$S$3))+MAX(0,MIN($T$3,MOD($O4,1))-MAX($W$3,MOD($N4,1)))),(WEEKDAY($N4,2)<6)*(MAX(0,$T$3-MAX($W$3,MOD($N4,1)))+MAX(0,$V$3-MAX($S$3,MOD($N4,1))))+(WEEKDAY($O4,2)<6)*(MAX(0,MIN($V$3,MOD($O4,1))-$S$3)+MAX(0,MIN($T$3,MOD($O4,1))-$W$3))+IF(INT($O4)-INT($N4)>1,($T$3-$W$3+$V$3-$S$3)*NETWORKDAYS(INT($N4)+1,INT($O4)-1),0)),"")
 
Last edited:
Upvote 0
I suggest to look at this thread:

One additional functionality might be a break, but the next can be a bank holiday, and for this a good (maybe even best) practice is a function approach which encapsulates all of it.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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