Reputation: 53
I'm trying to find number of products sold in +/- 5 business days from a particular date. I have a utlitiy function which tells whether the date is business day or non business day but I'm unable to figure out how do I use that in my query to determine +/5 - business days from a fixed date.
This is my query
Declare @MarketDate datetime= '2022-05-01'
select * from products
where Saledate between @MarketDate-5 and @MarketDate+5
I have a utlity to find business days between two dates but not sure how to use that within my query [udfUtility_DateRange](@DATE_FROM, @DATE_TO) - this gives me the business days between two dates
Upvotes: 1
Views: 51
Reputation: 21
Is this what you need? It is based on mysql. You can +/- the date relative to the current one.
SELECT * FROM products WHERE saledate >= DATE_ADD(curdate(), INTERVAL -5 DAY) AND saledate <= DATE_ADD(curdate(), INTERVAL +5 DAY)
Upvotes: 2