I have a query which is working fine. The query basically retrieves data between 6-8 days old from current date. I'd like exclude the weekends when measuring the age of the data.
Example: If a record is registered Friday, then Monday morning it will show like it's 4 days old, but it's actually only 2 days old, because Satuday and Sunday shouldn't count.
I tried this, which does not seem to be working:
Select id, name, CreatedDate
from table
where
CreatedDate <= DATEADD(day, -6, GETDATE()) AND CreatedDate >= DATEADD(day, -8, GETDATE()) -- here I get data between 6-8 days old
AND ((DATEPART(dw, CreatedDate) + @@DATEFIRST) % 7) NOT IN (0, 1) -- Here im trying to exclude weekends
What am I doing wrong?