For a given date I want to add business days to it. For example, if today is 10-17-2022 and I have a field that is 8 business days. How can I add 8 business days to 10-17-2022 which would be 10-27-2022.
Current Data:
BUSINESS_DAYS | Date |
---|---|
8 | 10-11-2022 |
10 | 10-13-2022 |
9 | 10-12-2022 |
Desired Output Data
BUSINESS_DAYS | Date | FINAL_DATE |
---|---|---|
8 | 10-11-2022 | 10-21-2022 |
10 | 10-13-2022 | 10-27-2022 |
9 | 10-12-2022 | 10-25-2022 |
As you can see we are skipping all weekends. We can ignore holidays for now.
Update: Using The suggest logic I got the following answer. I changed the names up. I used:
DATE_ADD(A.PO_SENT_DATE , INTERVAL
(CAST(PREDICTED_LEAD_TIME AS INT64)
+ (date_diff(A.PO_SENT_DATE , DATE_ADD(A.PO_SENT_DATE , INTERVAL CAST(PREDICTED_LEAD_TIME AS INT64) DAY), week)* 2))
DAY) as FINAL_DATE
Update2: Using the following:
DATE_ADD(`Date`, INTERVAL
(BUSINESS_DAYS
+ (date_diff( DATE_ADD(`Date`, INTERVAL BUSINESS_DAYS DAY),`Date`, week) * 2))
DAY) as FINAL_DATE
There are instances where the result falls on the weekend. See screenshot below. 10-22-2022 falls on a Saturday.