David Bentzon-Ehlers David Bentzon-Ehlers - 4 months ago 8
SQL Question

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.

Answer

Use the INTERVAL function:

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