Dec 28 2022 12:20 PM
Dec 28 2022 12:20 PM
I know that this is pretty easy for this group, but it's escaping me at the moment. I want to calculate the hours between two fields, but I just want a simple number of hours. No concatenated labels, not days, just accumulated hours and I need it to exclude weekends.
11/4/22 5:02 PM - 11/10/22 10:42 AM (minus weekends) = # of hours
Dec 28 2022 12:39 PM - edited Dec 28 2022 12:47 PM
I think this is same as another question:
here is my answer there:
= NETWORKDAYS(C2,D2) - 1 + MOD(D2,1) - MOD(C2,1)
and format cells as [h]:mm:ss as you noted.
but again this doesn't take into account any work hours and doesn't account for any start or end dates that are on the weekend.
If the start or end might be a weekend then try:
= NETWORKDAYS(C2,D2) - NETWORKDAYS(C2,C2) - NETWORKDAYS(D2,D2) + 1 + MOD(D2,1) - MOD(C2,1)
EDIT after thinking about this if it starts or end on a weekend then the MOD parts (the hours) shouldn't count either so:
= NETWORKDAYS(C2,D2) - NETWORKDAYS(C2,C2)*(1+MOD(C2,1)) - NETWORKDAYS(D2,D2)*(1- MOD(D2,1) ) + 1
Dec 28 2022 12:45 PM
Thank you for replying.
Sorry, I didn't even think to include start-end times.
lower / upper ranges for the start of the workday would be 7:00 AM and the end would be 11:00 PM.
Dec 28 2022 01:29 PM
Dec 28 2022 01:36 PM
Dec 29 2022 07:36 AM
@NeilKloster so in order to account for every contingency the formula is large but hopefully understandable:
= LET(StartDay, C7, EndDay, D7, DayStart, TIME(7,0,0), DayEnd, TIME(23,0,0), incStart,NETWORKDAYS(StartDay, StartDay), incEnd,NETWORKDAYS(EndDay,EndDay), daysInBetween, NETWORKDAYS(StartDay,EndDay) - incStart - incEnd, hoursInBetween, daysInBetween*(DayEnd - DayStart), startHours, incStart*MAX(DayEnd - MAX(DayStart,MOD(StartDay,1)),0), endHours, incEnd*MAX(MIN(DayEnd,MOD(EndDay,1))-DayStart,0), IF(daysInBetween>=0, startHours + hoursInBetween + endHours, if(StartDay<EndDay, MIN(DayEnd,MOD(EndDay,1))-MAX(DayStart,MOD(StartDay,1)),0)))
so row 1 is the only thing you need to enter with the start day & end day, and then DayStart and DayEnd are the start and end of the work hours. After that:
lines 2&3: the incStart & incEnd check if the start/end days are weekdays or weekends,
line 4: daysInBetween finds how many valid workdays NOT counting the 1st or last,
line 5: converts full days to # of work hours,
line 6&7: calculate the # hours on the 1st and last days
line 8: checks if # daysInBetween is valid (i.e. Start Day is > End Day)
line 9: adds hours together in 'normal' cases
line 10: calculates # hours if start Day is same as end Day or gives 0 if start is AFTER end
Dec 29 2022 01:27 PM
Okay, first and foremost - you are awesome! The amount of effort you are putting into this to help me is amazing! TYSM!!
So I put in that amazing formula and I'm getting results, but they are off. I am including a simplified file example to show you what is going on. Please ignore the conditional format coloring on column C.
Dec 29 2022 01:55 PMSolution
@NeilKloster So there are 2 things happening here:
a) any of the lines with start and end being the same day are 0 because you missed the last line of the equation
b) the numbers look weird because you didn't format them to show [h]:mm
If you want purely hours (i.e. [h]:mm of 1:30 would be 1.5) then just add 24* at the beginning (or *24 at the end) of the equation.
Dec 29 2022 02:12 PM
A shorter formula that works if neither Date/Time Opened not Date/Time Closed will be a weekend day:
Dec 29 2022 06:06 PM
Dec 29 2022 06:11 PM
Jan 13 2023 11:45 AM
So now the client has come back and asked for holidays to also be excluded. I know that there is a way to do this, by creating a list of dates, but when I tried it, it didn't work for me. Any thoughts on how to include this as well?
Jan 13 2023 12:05 PM
@NeilKloster you should only need to add a list of holidays in the workbook and refer to that list in the NETWORKDAYS formulas. In the attached I added a sheet with a HOLIDAYS tab I created for one of my companies and you can 'turn on'/'turn off' different holidays and add years to the Year column and the corresponding holiday dates are calculated.
On Sheet1 is both my formulas (output in H:MM vs # hours) and the alternate formula from @Hans Vogelaar and both have been updated with the holidays reference. Note there are a few output differences between the 2 so use whichever works for you.
Jan 18 2023 12:21 PM - edited Jan 18 2023 12:25 PM
Appreciate it BTW. @Sorry to ask again - the client came back this morning apologetic, with how they want to track these cases. The don't want business hours, they only want business days and they explained differently how they want this tracked. LOL!
So basically, if a case comes in from 6 AM - 7 PM (M-F), it needs to be completed in 1 business day, meaning no later than 7 PM the next business day. The way that I have everything setup now, if I change the time on the Date/Time closed column past 7 PM, everything stays the same.
I think I'm missing something simple, where basically I need to have a column that indicates that the value in the Date/Time Closed is past 7 PM, but I think I've looked at this time enough that I'm blind to it.
This is correct since the date/time closed is under 7 PM
This is not correct since the date/time closed is past 7PM
It should read 2.00 business days since the date/time closed is past the 7pm cut-off.
I tried doing even just a "-1" on the business days column, which would remove a day, but that doesn't ultimately do anything since I need the formula to be time sensitive to when it was closed. Adding an attachment sample - any help again is appreciated. Sorry for constantly asking.
Jan 18 2023 01:14 PM - edited Jan 18 2023 01:20 PM
so basically you need to 'make' anything after 7PM the next day so simply add 5/24 to force the any time after 7pm to be the next day (the morning hours becoming later that same day don't matter). So simply =NETWORKDAYS(start, end+5/24, holidays)-1 will work ....... ALMOST. The problem will come in when it starts on Th and end after 7pm Fri since that would become Sat and NETWORKDAYS will ignore Sat (or any of the holidays). So if we assume we don't care what day it is, if it is after 7pm then +1 workday then maybe:
=NETWORKDAYS(start, end, holidays) -1 + (MOD(end,1)>19/24)
Jan 18 2023 04:53 PM
Sort of - so basically it would be the next business day, so if it comes in after Thursday at 7 PM, it is considered Friday's business day. If it comes in after Friday at 7 PM, then it would be considered Monday's business day (unless it's a holiday).
(So many conditions). Phew.
6 AM - 7 PM (M-F) Business Hours.
If it comes in between 6 AM - 7 PM on a Monday, then the team has until 7 PM the next business day (Tuesday) to complete it. If it comes in after 7 PM on a Monday, then it is considered the next business day (Tuesday) and the team has until Weds at 7 PM to complete it. Does that help?
Jan 18 2023 05:02 PM
So just looking that file that you sent back, I ran through a few scenarios with weekends and it looks like it works correctly. I ran through it with just the normal work weeks and also tried it out on a holiday and it seems to work correctly. But it sounded like you thought that there was another issue?
Jan 18 2023 05:41 PM
Jan 19 2023 07:01 AM
Think I got it all setup (hopefully unless they come back with changes). Once again, I really, REALLY want to thank you for all your help! I really appreciate it greatly!