exclude non-business hours and weekends

KARANDREA

New Member
Joined
Jul 3, 2020
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
Thanks in advance for any help that can be offered.
I need to calculate the time between Assign date & Owned Date, but i must exclude weekends, if exists, and non business hours.
I am using ths formula at G column :
=(NETWORKDAYS(IF(WEEKDAY(D2;2)>5;WORKDAY(D2;1)+1/3;D2);E2)-1+MOD(E2;1)-MOD(IF(WEEKDAY(D2;2)>5;WORKDAY(D2;1)+1/3;D2);1))
It exclude weekends and start counting from Next business day from 8:00.

But i have different support hours, as example line 9, so i need to modify my formula with business hours in columns B & C.

I tried this formula in column H
=(NETWORKDAYS(D2;E2)-1)*(C2-B2)+IF(NETWORKDAYS(E2;E2);MEDIAN(MOD(E2;1);C2;B2);C2)-MEDIAN(NETWORKDAYS(D2;D2)*MOD(D2;1);C2;B2)
but i can't find out how change it in order start counting from Next business day. As example it gives me wrong result in cell H3.

1593784062323.png


I am confused.

Please help!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
It is preferable that you attach any samples using the XL2BB add in (green button on the reply toolbar), that way we can copy and paste your sample and formulas to excel for testing without having to retype everything.

Based on how you describe what you're trying to do, I think that this slight change to your first formula might do what you need.

=(NETWORKDAYS(IF(WEEKDAY(D2;2)>5;WORKDAY(D2;1)+B2;D2);E2)-1+MOD(E2;1)-MOD(IF(WEEKDAY(D2;2)>5;WORKDAY(D2;1)+B2;D2);1))

If that doesn't give you the correct results, please overtype the incorrect results with the expected result, then post your sample again using XL2BB
 
Upvote 0
Shouldn't G18 and G19 both be zero because the times are outside the business hours?
 
Upvote 0
Thank you very much for your reply.

There is a problem in lines 18,19, 23 for example it should give me as result zero "0:00" because the ticket has been reported at non -business hours and in line 20 it should give as result "2:55" . It should start counting from next business day.



XFProjects test.xlsx
BCDEG
1SUPPORT START TIMESUPORT END TIMEAssign DateOwned Date
208:0018:0015/1/2020 13:4415/1/2020 14:000:16
308:0018:0011/1/2020 18:5413/1/2020 09:161:16
408:0018:0010/1/2020 17:0310/1/2020 17:050:02
508:0018:0016/1/2020 10:3016/1/2020 10:430:13
608:0018:0014/1/2020 13:2814/1/2020 13:300:02
708:0018:0017/1/2020 13:4817/1/2020 14:060:18
808:0018:0020/1/2020 09:4920/1/2020 09:580:09
909:0018:0027/1/2020 13:2327/1/2020 15:171:54
1008:0018:0031/1/2020 15:2731/1/2020 15:310:04
1108:0018:001/2/2020 10:433/2/2020 08:230:23
1208:0018:003/2/2020 13:193/2/2020 13:310:12
1308:0018:008/2/2020 16:2610/2/2020 08:280:28
1408:0018:006/3/2020 18:469/3/2020 10:1515:29
1508:0018:008/5/2020 09:068/5/2020 09:360:30
1608:0018:0011/5/2020 14:3811/5/2020 15:260:48
1708:0018:0011/5/2020 14:3311/5/2020 15:270:54
1808:0018:002/3/2020 19:112/3/2020 20:221:11
1908:0018:002/3/2020 19:092/3/2020 20:241:15
2008:0018:0019/5/2020 21:1120/5/2020 10:5513:44
2108:0018:0018/5/2020 16:3318/5/2020 16:420:09
2208:0018:0018/5/2020 16:3218/5/2020 16:420:10
2308:0018:0018/5/2020 19:5718/5/2020 21:141:17
all
Cell Formulas
RangeFormula
B2:B23B2=IF(ISNUMBER(SEARCH("LUFTHANSA", A2,1)),"08:00", IF(ISNUMBER(SEARCH("H&M", A2,1)),"08:00", IF(ISNUMBER(SEARCH("ACCORHOTELS", A2,1)),"08:00", IF(ISNUMBER(SEARCH("WARTSILA (FIN)", A2,1)),"08:00", IF(ISNUMBER(SEARCH("RALPH", A2,1)),"09:00", IF(ISNUMBER(SEARCH("CENTURYLINK", A2,1)),"08:00", IF(ISNUMBER(SEARCH("ORION", A2,1)),"08:00", IF(ISNUMBER(SEARCH("BOREALIS", A2,1)),"08:00", "09:00" ))))))))
C2:C23C2=IF(ISNUMBER(SEARCH("LUFTHANSA", A2,1)),"18:00", IF(ISNUMBER(SEARCH("H&M", A2,1)),"18:00", IF(ISNUMBER(SEARCH("ACCORHOTELS", A2,1)),"18:00", IF(ISNUMBER(SEARCH("WARTSILA (FIN)", A2,1)),"18:00", IF(ISNUMBER(SEARCH("RALPH", A2,1)),"18:00", IF(ISNUMBER(SEARCH("CENTURYLINK", A2,1)),"18:00", IF(ISNUMBER(SEARCH("ORION", A2,1)),"18:00", IF(ISNUMBER(SEARCH("BOREALIS", A2,1)),"18:00", "17:00" ))))))))
G2:G23G2=(NETWORKDAYS(IF(WEEKDAY(D2,2)>5,WORKDAY(D2,1)+1/3,D2),E2)-1+MOD(E2,1)-MOD(IF(WEEKDAY(D2,2)>5,WORKDAY(D2,1)+1/3,D2),1))
 
Upvote 0
G14 is also wrong. It should be 2:15. Your first formula doesn't work.
 
Upvote 0
To avoid any confusion as to what is actually required, could you please do as I asked in my earlier post
please overtype the incorrect results with the expected result, then post your sample again using XL2BB
As @yky has noticed, there appear to be incorrect results in more rows that those that you have drawn attention to so please check them carefully, thanks.
 
Upvote 0
Thank you very much for your attention.

@yky I gave the lines as example. The formula doesn't work. This is just a sample from my file.


@jasonb75 In column H is the results that i should have. The formula should count hours only if the time is between "B" & "C" and if the time is out of this range it should return 0:00.




XFProjects test.xlsx
BCDEGH
1SUPPORT START TIMESUPORT END TIMEAssign DateOwned Dateformula resultcorrect result
208:0018:0015/1/2020 13:4415/1/2020 14:000:160:16
308:0018:0011/1/2020 18:5413/1/2020 09:161:161:16
408:0018:0010/1/2020 17:0310/1/2020 17:050:020:02
508:0018:0016/1/2020 10:3016/1/2020 10:430:130:13
608:0018:0014/1/2020 13:2814/1/2020 13:300:020:02
708:0018:0017/1/2020 13:4817/1/2020 14:060:180:18
808:0018:0020/1/2020 09:4920/1/2020 09:580:090:09
909:0018:0027/1/2020 13:2327/1/2020 15:171:541:54
1008:0018:0031/1/2020 15:2731/1/2020 15:310:040:04
1108:0018:001/2/2020 10:433/2/2020 08:230:230:23
1208:0018:003/2/2020 13:193/2/2020 13:310:120:12
1308:0018:008/2/2020 16:2610/2/2020 08:280:280:28
1408:0018:006/3/2020 18:469/3/2020 10:1515:292:15
1508:0018:008/5/2020 09:068/5/2020 09:360:300:30
1608:0018:0011/5/2020 14:3811/5/2020 15:260:480:48
1708:0018:0011/5/2020 14:3311/5/2020 15:270:540:54
1808:0018:002/3/2020 19:112/3/2020 20:221:110:00
1908:0018:002/3/2020 19:092/3/2020 20:241:150:00
2008:0018:0019/5/2020 21:1120/5/2020 10:5513:442:55
2108:0018:0018/5/2020 16:3318/5/2020 16:420:090:09
2208:0018:0018/5/2020 16:3218/5/2020 16:420:100:10
2308:0018:0018/5/2020 19:5718/5/2020 21:141:170:00
all
 
Upvote 0
This is what I got. The formula will cover if shift spans more than one day as in row 27. If this is not necessary, the formula would be shorter.

hours.xlsx
ABCDEFG
11SUPPORT START TIMESUPORT END TIMEAssign Date ▼Owned Date ▼'T
228:00:00 AM6:00:00 PM1/15/2020 13:441/15/2020 14:000:160:16
338:00:00 AM6:00:00 PM1/11/2020 18:541/13/2020 9:161:161:16
448:00:00 AM6:00:00 PM1/10/2020 17:031/10/2020 17:050:020:02
558:00:00 AM6:00:00 PM1/16/2020 10:301/16/2020 10:430:130:13
668:00:00 AM6:00:00 PM1/14/2020 13:281/14/2020 13:300:020:02
778:00:00 AM6:00:00 PM1/17/2020 13:481/17/2020 14:060:180:18
888:00:00 AM6:00:00 PM1/20/2020 9:491/20/2020 9:580:090:09
999:00:00 AM6:00:00 PM1/27/2020 13:231/27/2020 15:171:541:54
10108:00:00 AM6:00:00 PM1/31/2020 15:271/31/2020 15:310:040:04
11118:00:00 AM6:00:00 PM2/1/2020 10:432/3/2020 8:230:230:23
12128:00:00 AM6:00:00 PM2/3/2020 13:192/3/2020 13:310:120:12
13138:00:00 AM6:00:00 PM2/8/2020 16:262/10/2020 8:280:280:28
14148:00:00 AM6:00:00 PM3/6/2020 18:463/9/2020 10:1515:292:15
15158:00:00 AM6:00:00 PM5/8/2020 9:065/8/2020 9:360:300:30
16168:00:00 AM6:00:00 PM5/11/2020 14:385/11/2020 15:260:480:48
17178:00:00 AM6:00:00 PM5/11/2020 14:335/11/2020 15:270:540:54
18188:00:00 AM6:00:00 PM3/2/2020 19:113/2/2020 20:221:110:00
19198:00:00 AM6:00:00 PM3/2/2020 19:093/2/2020 20:241:150:00
20208:00:00 AM6:00:00 PM5/19/2020 21:115/20/2020 10:5513:442:55
21218:00:00 AM6:00:00 PM5/18/2020 16:335/18/2020 16:420:090:09
22228:00:00 AM6:00:00 PM5/18/2020 16:325/18/2020 16:420:100:10
23238:00:00 AM6:00:00 PM5/18/2020 19:575/18/2020 21:141:170:00
24248:00:00 AM6:00:00 PM5/24/2020 7:525/24/2020 19:520:00
25258:00:00 AM6:00:00 PM5/22/2020 7:525/23/2020 10:2210:00
26268:00:00 AM6:00:00 PM5/22/2020 7:525/25/2020 6:2310:00
27279:00:00 AM6:00:00 PM5/21/2020 7:525/23/2020 19:2118:00
Sheet1
 
Upvote 0
Not sure why the formula doesn't show up. Maybe because it's so long. Hope someone can come up with a shorter formula.

=IF(IF(WEEKDAY(E2,2)>5,WORKDAY(E2,1)+C2-3,IF(AND(WEEKDAY(E2,2)=1,MOD(E2,1)<=B2),WORKDAY(E2,1)+C2-4,IF(MOD(E2,1)<MOD($C2,1),E2,WORKDAY(INT(E2),0)+C2)))<IF(OR(WEEKDAY(D2,2)>5,AND(WEEKDAY(D2,2)=5,MOD(D2,1)>C2)),WORKDAY(D2,1)+B2,IF(MOD(D2,1)>B2,IF(MOD(D2,1)>C2,WORKDAY(D2,1)+B2,D2),INT(D2)+B2)),0,IF(IF(WEEKDAY(E2,2)>5,WORKDAY(E2,1)+C2-3,IF(AND(WEEKDAY(E2,2)=1,MOD(E2,1)<=B2),WORKDAY(E2,1)+C2-4,IF(MOD(E2,1)<MOD($C2,1),E2,WORKDAY(INT(E2),0)+C2)))-IF(OR(WEEKDAY(D2,2)>5,AND(WEEKDAY(D2,2)=5,MOD(D2,1)>C2)),WORKDAY(D2,1)+B2,IF(MOD(D2,1)>B2,IF(MOD(D2,1)>C2,WORKDAY(D2,1)+B2,D2),INT(D2)+B2))>1,IF(WEEKDAY(E2,2)>5,WORKDAY(E2,1)+C2-3,IF(AND(WEEKDAY(E2,2)=1,MOD(E2,1)<=B2),WORKDAY(E2,1)+C2-4,IF(MOD(E2,1)<MOD($C2,1),E2,WORKDAY(INT(E2),0)+C2)))-IF(OR(WEEKDAY(D2,2)>5,AND(WEEKDAY(D2,2)=5,MOD(D2,1)>C2)),WORKDAY(D2,1)+B2,IF(MOD(D2,1)>B2,IF(MOD(D2,1)>C2,WORKDAY(D2,1)+B2,D2),INT(D2)+B2))-INT(IF(WEEKDAY(E2,2)>5,WORKDAY(E2,1)+C2-3,IF(AND(WEEKDAY(E2,2)=1,MOD(E2,1)<=B2),WORKDAY(E2,1)+C2-4,IF(MOD(E2,1)<MOD($C2,1),E2,WORKDAY(INT(E2),0)+C2)))-IF(OR(WEEKDAY(D2,2)>5,AND(WEEKDAY(D2,2)=5,MOD(D2,1)>C2)),WORKDAY(D2,1)+B2,IF(MOD(D2,1)>B2,IF(MOD(D2,1)>C2,WORKDAY(D2,1)+B2,D2),INT(D2)+B2)))*(1-C2+B2),IF(WEEKDAY(E2,2)>5,WORKDAY(E2,1)+C2-3,IF(AND(WEEKDAY(E2,2)=1,MOD(E2,1)<=B2),WORKDAY(E2,1)+C2-4,IF(MOD(E2,1)<MOD($C2,1),E2,WORKDAY(INT(E2),0)+C2)))-IF(OR(WEEKDAY(D2,2)>5,AND(WEEKDAY(D2,2)=5,MOD(D2,1)>C2)),WORKDAY(D2,1)+B2,IF(MOD(D2,1)>B2,IF(MOD(D2,1)>C2,WORKDAY(D2,1)+B2,D2),INT(D2)+B2))))
 
Upvote 0
This formula doesn't work.
If the range of support time is 8:00 - 18:00 and a ticket's "assigned time" is 19:45 and "owned time" is 21:00 the result should be 0 hours because it is out of support range.
Now If the ticket's "assigned time" is 19:45 and "owned time" is 8:30 the next business day, the result must be 30 minutes.
It shouldn't count weekends and non business hours.
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,239
Members
448,879
Latest member
VanGirl

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