I want to write a query which will return records where the due date ( will be calculated from start and end date ) is within next 5 business dayes ( exclude weekends)
I tried the following but this is not considering business days:
`SELECT *
FROM table
WHERE (CURRENT_DATE - end_date) <= INTERVAL '5 days' `
2
Answers
You could use DATEDIFF() in mysql
For example : https://onecompiler.com/mysql/42f8pap49
For Postgres, just substract you dates like this : https://onecompiler.com/postgresql/42f8q4rmh
For your case (5 work days) simple query
For monday(isodow=1) direct add 4 days – friday is due date.
Else additional 2 days (weekend) add to current date.
Other, longer, weekends don’t matter.