=IF(CR13<>"",(CT13-CR13)+1,"") the formula works on dates in CR & CT cells. How do I…
- User
=IF(CR13<>"",(CT13-CR13)+1,"") the formula works on dates in CR & CT cells. How do I omit Weekends from the calculation
- Assistant
You can modify the formula to exclude weekends by adding an IF statement that checks if the day of the week is a weekend (Saturday or Sunday) before calculating the difference. Here is an example of how you can modify the formula:
=IF(CR13<>"" ,IF(OR(WEEKDAY(CR13)=1,WEEKDAY(CR13)=7),"", (CT13-CR13)+1),"")
In this modified formula, the WEEKDAY function is used to check if the day of the week for the date in CR13 is either Sunday (1) or Saturday (7). If it is either of these days, the formula returns an empty string (""), effectively skipping the calculation for weekends. Otherwise, it calculates the difference between the two dates as before.
- User
in most cases the day in CR will be before the week end and the day in CT might be after a weekend. How will it the omit calculation of the weekend in its result
- Assistant
To omit weekends from the calculation while accounting for cases where the start date and end date may fall on different sides of a weekend, you can use a more complex formula that calculates the total number of weekend days between the two dates and subtracts this from the overall difference.
Here is a formula that can achieve this:
=IF(CR13<>"", (CT13-CR13)+1 // Calculate total days including weekends
- SUMPRODUCT((WEEKDAY(ROW(INDIRECT(CR13 & ":" & CT13)))=1)+(WEEKDAY(ROW(INDIRECT(CR13 & ":" & CT13)))=7)) // Subtract weekends
- MAX(0, SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(CR13 & ":" & CT13)))=1))*(WEEKDAY(CT13)=1)
- MAX(0, SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(CR13 & ":" & CT13)))=7))*(WEEKDAY(CT13)=7), " ")
This formula calculates the total number of days between CR13 and CT13, including weekends, then subtracts the total number of weekend days between the two dates. Additionally, it checks for cases where the end date falls on a weekend day and if the weekend days should be subtracted.
This formula is quite complex, so I recommend testing it thoroughly with your data to ensure it works as expected.
- User
there is a syntax error with the formula
- Assistant
I apologize for the error in the formula. Let's simplify the formula to exclude weekends from the calculation, particularly when the start date and end date might be on different sides of a weekend.
Here is an updated formula that should work correctly:
=IF(CR13<>"", NETWORKDAYS.INTL(CR13, CT13, "1111111") + 1 - IF(AND(WEEKDAY(CR13)=7, WEEKDAY(CT13)=1), 2, IF(WEEKDAY(CR13)=7, 1, IF(WEEKDAY(CT13)=1, 1, 0))), "")In this formula:
- NETWORKDAYS.INTL function calculates the network days between two dates, excluding weekends based on the weekend parameter "1111111" (which marks Saturday and Sunday as weekend days).
- We add 1 to the result as we want to include the start day in the count.
- We then subtract 1 for any partial weekend day at the start date, or 1 for any partial weekend day at the end date, or 2 if both are partial weekend days.
This should provide the correct number of working days between the two dates, excluding weekends. Let me know if there are any specific requirements or additional conditions you would like to add to the calculation.