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

时间:2016-07-11 20:06:24

标签: sql postgresql

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.

2 个答案:

答案 0 :(得分:1)

Use the INTERVAL function:

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

答案 1 :(得分:0)

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())