If today is Friday, I would like to get data 7 to 9 days from now, if not 7 days. I am using SQL Server.
Before:
id | class | startdate |
---|---|---|
1 | English | 2020-12-21 00:00:00.000 |
2 | English | 2020-12-22 00:00:00.000 |
3 | Math | 2020-12-21 00:00:00.000 |
4 | English | 2020-12-27 00:00:00.000 |
5 | Math | 2020-12-27 00:00:00.000 |
If today is 14/12/2020 - Monday, it will produce the result below:
id | class | startdate |
---|---|---|
1 | English | 2020-12-21 00:00:00.000 |
3 | Math | 2020-12-21 00:00:00.000 |
I tried the following, but it doesn't work.
select id, class, startdate
from class
where case datepart(w, GETDATE())
when 6 then startdate between DateAdd(dd,+9,GETDATE() ) and DateAdd(dd,+10,GETDATE()))
else startdate between DateAdd(dd,+7,GETDATE() ) and DateAdd(dd,+8,GETDATE()))
end
order by startdate