Hours Between 2 Dates Excluding Non-Business Hours ONLY

j0eyjedi

New Member
Joined
Sep 19, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Can someone please help me calculate the hours between 2 dates, excluding non-business hours ONLY.

I do not believe the "NETWORKDAYS" function will work in this example as I do not want to exclude weekends, only non-business hours are excludable.

Example:
Excludable Non-Business Hours = 10pm - 9am
Start Time = 9/19/24 9:00 pm
End Time = 9/20/24 9:00 am

The result should be 1 hour (9pm-10pm = 1 hour and all other non business hours are excluded)

I've tried several formulas using median and mod, but I'm stuck.

Any help is greatly appreciated!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Here's a couple of different options depending on how you have input your date/time.

j0eyjedi.xlsx
ABCDEF
1Start dateStart timeEnd dateEnd time
219/09/202421:0020/09/20249:001
319/09/2024 21:0020/09/2024 9:001
Sheet1
Cell Formulas
RangeFormula
F2F2=((C2-A2)*("22:00"-"9:00")+D2-B2)*24
F3F3=((INT(C3)-INT(A3))*("22:00"-"9:00")+TIME(HOUR(C3),MINUTE(C3),SECOND(C3))-TIME(HOUR(A3),MINUTE(A3),SECOND(A3)))*24
 
Upvote 0
Here's a couple of different options depending on how you have input your date/time.

j0eyjedi.xlsx
ABCDEF
1Start dateStart timeEnd dateEnd time
219/09/202421:0020/09/20249:001
319/09/2024 21:0020/09/2024 9:001
Sheet1
Cell Formulas
RangeFormula
F2F2=((C2-A2)*("22:00"-"9:00")+D2-B2)*24
F3F3=((INT(C3)-INT(A3))*("22:00"-"9:00")+TIME(HOUR(C3),MINUTE(C3),SECOND(C3))-TIME(HOUR(A3),MINUTE(A3),SECOND(A3)))*24
Hey Murray,

Thank you for your help!

I entered your formula and it returned 1 when the format of the column was a "Number", but when i formatted the column to display as "Hours" (13:30) the result was incorrect.

I attached a screenshot below. Column (J) shows the result that I would like to have calculated in column (G)

Any help is appreciated!
 

Attachments

  • Screenshot 2024-09-19 085509.png
    Screenshot 2024-09-19 085509.png
    23.2 KB · Views: 6
Upvote 0
Here's a couple of different options depending on how you have input your date/time.

j0eyjedi.xlsx
ABCDEF
1Start dateStart timeEnd dateEnd time
219/09/202421:0020/09/20249:001
319/09/2024 21:0020/09/2024 9:001
Sheet1
Cell Formulas
RangeFormula
F2F2=((C2-A2)*("22:00"-"9:00")+D2-B2)*24
F3F3=((INT(C3)-INT(A3))*("22:00"-"9:00")+TIME(HOUR(C3),MINUTE(C3),SECOND(C3))-TIME(HOUR(A3),MINUTE(A3),SECOND(A3)))*24

In this screenshot column G is formatted as "Number" and column H is formatted as "Time (13:30)"
 

Attachments

  • Screenshot 2024-09-19 090601.png
    Screenshot 2024-09-19 090601.png
    25 KB · Views: 8
Upvote 0
Another opcion:

Column A and B formatted as "dd/mm/yyyy hh:mm"
Column C formatted as "[h]:mm"

TimeDiff.xlsx
ABC
1StartEndDifference [h:mm]
211/09/2024 21:0012/09/2024 09:001:00
311/09/2024 21:0012/09/2024 10:002:00
420/09/2024 21:0023/09/2024 09:0027:00
Sheet1 (2)
Cell Formulas
RangeFormula
C2:C4C2=LET( t_1, A2, t_2, B2, n, ROUND((t_2-t_1)*24*60, 0), s, SEQUENCE(n,,t_1, TIME(0,1,0)), m, VALUE(TEXT(s, "hh:mm")), isWorkingHour, (m>= VALUE("9:00"))*(m<VALUE("22:00")), res, SUM(isWorkingHour)/24/60, res )
 
Upvote 0
Solution
I entered your formula and it returned 1 when the format of the column was a "Number", but when i formatted the column to display as "Hours" (13:30) the result was incorrect.
What do you mean the result was ‘incorrect’. A result of 1 hour will never format as 13:30 - it will format as ‘01:00’.
Can you also explain your calculations for row 5 in your images, or perhaps it’s just a mistake? Your working day is from 09:00 to 22:00 (13 hours), so for row 5:
Commencing 01:00 on the 16th will be 13 hours on that day plus another 13 for each of the 17th and 18th respectively, then 1 hour 10 minutes on the 19th gives (13*3)+1:10=40:10, but column K says 27:10?
 
Upvote 0
Another opcion:

Column A and B formatted as "dd/mm/yyyy hh:mm"
Column C formatted as "[h]:mm"

TimeDiff.xlsx
ABC
1StartEndDifference [h:mm]
211/09/2024 21:0012/09/2024 09:001:00
311/09/2024 21:0012/09/2024 10:002:00
420/09/2024 21:0023/09/2024 09:0027:00
Sheet1 (2)
Cell Formulas
RangeFormula
C2:C4C2=LET( t_1, A2, t_2, B2, n, ROUND((t_2-t_1)*24*60, 0), s, SEQUENCE(n,,t_1, TIME(0,1,0)), m, VALUE(TEXT(s, "hh:mm")), isWorkingHour, (m>= VALUE("9:00"))*(m<VALUE("22:00")), res, SUM(isWorkingHour)/24/60, res )
That worked! thank you so much!
 
Upvote 0

Forum statistics

Threads
1,223,877
Messages
6,175,137
Members
452,614
Latest member
MRSWIN2709

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