Elitmiar
Elitmiar

Reputation: 36839

Getting all records that are 3months old in Postgres

I need to find all records that are exactly 3months old in Postgres

My query looks as follows.

SELECT * FROM adds WHERE adtype = 'CL' AND DATEDIFF(dstart,DATE(now())) = DATE_SUB(curdate(),interval 3 month);

But this does not seem to work. Any advise help with this query will be helpful. I can calculate this in PHP but want to find out the value using a Postgres query.

Upvotes: 0

Views: 377

Answers (1)

AndreKR
AndreKR

Reputation: 33678

  1. You are comparing a time period to a point in time.
  2. Is there really a DATEDIFF in Postgres?
  3. Are you sure you need the records of that one day exactly 3 months in the past? Unusual application.

I'd suggest: WHERE DATE(dstart) = DATE(NOW())-INTERVAL '3 month'

Upvotes: 1

Related Questions