I need to write a view where I need to select all the elements where the date is between today and + 7 days.
I have for example:
2018-11-30
2018-06-30
2018-10-31
2018-05-31
2018-04-16
2018-04-12
2018-04-02
From this list I need only these two elements:
2018-04-16
2018-04-12
I have tried already like this:
WHERE sl.GettingBackDate > CAST(DATEADD(DAY, -7, GETDATE()) as DATE)
but this returns all the elements where the date is greater than today
WHERE sl.GettingBackDate BETWEEN DATEADD(DAY,-7,GETDATE()) AND GETDATE()
this don't return any element
I created an SQLFiddle - http://sqlfiddle.com/#!18/27d5c/2
Can you advise?
You can add the following where condition
WHERE
sl.GettingBackDate >= CONVERT(DATE, GETDATE()) AND
sl.GettingBackDate <= CONVERT(DATE,DATEADD(DAY,7,GETDATE()))
Use this double filter.
WHERE
sl.GettingBackDate >= CONVERT(DATE, GETDATE()) AND -- From today onwards
sl.GettingBackDate < CONVERT(DATE, GETDATE() + 8) -- Less than 8 days from now (strict)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With