Issue with finding time difference taking account of weekends and workdays.

BigGee

New Member
Joined
Sep 8, 2020
Messages
29
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,
I am having trouble calculating a time difference between 2 x calculated dates taking into account workdays / weekends and working hours. Could someone help me coming up with a working formula?
I have tried NETWORKDAYS - but don't know how to account for working hours.

My problem is that I have the following working days
Mon-Thu - 6.30 - 3.30pm with 15min break at 9.30 and 30 min break at 12.30
Fri - 6.30-11.45 with 15min break at 9.30

Would appreciate any help

Thanks

1726491830888.png
 
Would this work?:

I also consideres if time difference in negative. If that is never going to happen and if you need the time difference to be a number and not a text, then that is an easy fix.

U2:U3 is formatted as a table named T_Holidays where you can add all your holidays.
result in column G, H, I is formatted as "[h]:mm".

Book1.xlsx
ABCDEFGHIJKLMNOPQRSTU
1Online DateTarget Offline DateActual OfflineOnline To Target [h:mm]Online to Actual [h:mm]Difference [h:mm]
211/09/2024 07:3113/09/2024 14:5916/09/2024 08:3420:2922:332:04DaysShift StartShift endBreak Start 1Break end 1Break Start 2Break end 2Holidays
311/09/2024 09:1716/09/2024 10:0016/09/2024 10:4521:5822:430:45Mon-Thu06:3015:3009:3009:4512:3013:0017/09/2024
411/09/2024 11:1816/09/2024 11:4616/09/2024 11:4621:5821:580:00Fri06:3011:4509:3009:45
516/09/2024 15:2518/09/2024 06:3516/09/2024 15:300:100:05- 0:05
616/09/2024 15:2518/09/2024 06:3518/09/2024 06:550:100:300:20
716/09/2024 06:0016/09/2024 16:008:15
816/09/2024 06:0017/09/2024 16:008:15
916/09/2024 06:0018/09/2024 16:0016:30
1016/09/2024 06:0016/09/2024 16:00 8:15
1116/09/2024 06:0017/09/2024 16:00 8:15
1216/09/2024 06:0018/09/2024 16:00 16:30
1316/09/2024 09:2516/09/2024 09:5016/09/2024 09:510:100:110:01
1416/09/2024 12:2516/09/2024 13:0516/09/2024 13:060:100:110:01
Sheet1
Cell Formulas
RangeFormula
G2:I14G2=LET( timeBetween, LAMBDA(t_1,t_2, LET(n, ROUND((t_2-t_1)*24*60, 0), s, SEQUENCE(n,,t_1, TIME(0,1,0)), d, INT(s), m, VALUE(TEXT(s, "hh:mm")), isWorkingDay, WORKDAY.INTL(d-1, 1, 1, T_Holidays)=d, isWorkingHour, ((WEEKDAY(d, 2)<5)*(m>= $M$3)*(m<$N$3)*NOT((m>=$O$3)*(m<$P$3)+(m>=$Q$3)*(m<$R$3))+(WEEKDAY(d, 2)=5)*(m>= $M$4)*(m<$N$4)*NOT((m>=$O$4)*(m<$P$4)))>0, SUM(isWorkingDay*isWorkingHour)/24/60 )), onlineToTargetOffline, timeBetween(D2, E2), onlineToActualOffline, timeBetween(D2, F2), dif, onlineToActualOffline-onlineToTargetOffline, HSTACK(IFERROR(onlineToTargetOffline, ""), IFERROR(onlineToActualOffline, ""), IFERROR(IF(dif<0, "- ", "") & TEXT(ABS(dif), "[h]:mm"), "")) )
Dynamic array formulas.


Let me know if this works for you.
I am afraid this did not work, everything copied across, I had to change the formatting for columns D to F.
The format wouldnt work for row 6 column B down but did for the others??
No value in Column G,H or I. All the formulas are intact? If I click on G2 it does shadow out H and I2 - perhaps something basic I have done wrong?

1726730001048.png
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,221,470
Messages
6,160,029
Members
451,611
Latest member
PattiButche

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