I need a formula that will work in a saved search ...
# ask-stanley-ai
c
I need a formula that will work in a saved search that compares two date fields and finds the number of non-weekend days between the dates.
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that calculating the number of business days between two dates in a saved search can be quite complex. However, a formula was suggested in one of the threads that might work:
Copy code
code
Formula(Numeric) | to_char(last_day(trunc({today})),'DD')-((trunc(last_day({today}),'IW')-trunc(trunc({today},'MONTH'),'IW'))/7*2)-(decode(to_char(last_day(trunc({today})),'D'),1,2,7,1,0))+(decode(to_char(trunc({today},'MONTH'),'D'),1,1,0))
This formula calculates the number of days in the current month, subtracts the number of weekend days, and then adjusts for whether the first and last days of the month are weekends. However, it seems to always return 20 days, regardless of the actual number of business days in the month. To adjust this formula to calculate the number of business days between two specific dates, you would need to replace
{today}
with your date fields. However, this might not work as expected, as the formula is designed to calculate the number of business days in a month, not between two arbitrary dates. Unfortunately, it seems that there is no straightforward way to calculate the number of business days between two dates in a saved search. You might need to use a scripting solution, such as the
moment-business-days
npm package mentioned in one of the threads, but this would require writing a SuiteScript, which is outside the scope of a saved search. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.863708615
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.861999571
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.859253
Please provide your feedback on this answer.