C
C
CityzenUNDEAD2020-10-13 12:25:30
SQL
CityzenUNDEAD, 2020-10-13 12:25:30

How to make select by date interval correctly?

Hello everyone!
I need to select records in my database that are in the interval of the publication date of the record for the last 7 days. The PublishDate field is responsible for this.

Here such select correct in the given plan?

SELECT * FROM Table
WHERE AND PublishDate > '20201006' AND PublishDate < '20201014'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
idShura, 2020-10-13
@idShura

SELECT * FROM Table
WHERE PublishDate between '20201006' AND '20201014'

Or
SELECT * FROM Table
WHERE PublishDate >= DATEADD(day,-7, GETDATE())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question