Finding the working hours between two dates and times

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
HI Everyone,

Our workshop is open Monday to Friday 8am till 6pm,
In my sheet i have a begin time i.e. "20/01/2024 12.33" in A4 and end time i.e. "21/01/2024 9.30 am" in B4 i'd like a formula in C4 that can work out the hours it took, but only for hours within my working week so if its over the weekend it does count those days etc.
can someone please help with this formula as i'm stuck

Thanks

Tony
 
Modified formula.
Excel Formula:
=IF(AND($A7>0,$B7>0),IF(INT($B7)=INT($A7),MEDIAN($F$2,$G$2,MOD($B7,1))-MEDIAN($F$2,$G$2,MOD($A7,1)),IF(INT($B7)=INT($A7),MEDIAN($F$2,$G$2,MOD($B7,1))-MEDIAN($F$2,$G$2,MOD($A7,1)),$G$2-MAX($F$2,MOD($A7,1))+MIN(MOD($B7,1),$G$2)-$F$2+IF((INT($B7)-INT($A7))>1,NETWORKDAYS($A7+1,$B7-1)*($G$2-$F$2),0))),"")
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Revised formula
Excel Formula:
=IF(AND($A4>0,$B4>0),IF(INT($B4)=INT($A4),(WEEKDAY($A4,2)<6)*(MEDIAN($F$2,$G$2,MOD($B4,1))-MEDIAN($F$2,$G$2,MOD($A4,1))),IF(INT($B4)=INT($A4),MEDIAN($F$2,$G$2,MOD($B4,1))-MEDIAN($F$2,$G$2,MOD($A4,1)),$G$2-MAX($F$2,MOD($A4,1))+MIN(MOD($B4,1),$G$2)-$F$2+IF((INT($B4)-INT($A4))>1,NETWORKDAYS($A4+1,$B4-1)*($G$2-$F$2),0))),"")
 
Upvote 0
Try
Excel Formula:
=IF(AND($A2>0,$B2>0),IF(INT($B2)=INT($A2),(WEEKDAY($A2,2)<6)*(MEDIAN($F$2,$G$2,ROUND(MOD($B2,1),6))-MEDIAN($F$2,$G$2,ROUND(MOD($A2,1),6))),(WEEKDAY($A2,2)<6)*($G$2-MAX($F$2,ROUND(MOD($A2,1),6)))+(WEEKDAY($B2,2)<6)*(MIN(ROUND(MOD($B2,1),6),$G$2)-$F$2)+IF((INT($B2)-INT($A2))>1,NETWORKDAYS($A2+1,$B2-1)*($G$2-$F$2),0)),"")
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,084
Members
453,021
Latest member
Justyna P

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