DBE7
DBE7

Reputation: 816

How do I retrieve data that is within a specific date range?

I want to retrieve data from within 60 days of a created_at date. Here are two columns: SomeValueColumn, created_at. I only want data for each row of the SomeValueColumn WHERE the created_at date is within 60 days.

What is the most efficient way of doing this? I can't seem to figure out the where statement.

Upvotes: 1

Views: 69

Answers (2)

Aaron Dietz
Aaron Dietz

Reputation: 10277

Use the INTERVAL function:

SELECT SomeValueColumn, Created_At
FROM   YourTable
WHERE  Created_At > CURRENT_DATE - INTERVAL '60 days'

Upvotes: 1

Maarten Kieft
Maarten Kieft

Reputation: 7125

You need a where statement like this:

DATEADD(DAY,-60,GETDATE())

So your query will look like this:

SELECT SomeValueColumn, created_at FROM table WHERE DATEADD(DAY,-60,GETDATE())

Upvotes: 0

Related Questions