views:

28

answers:

1

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.

A: 
  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? Unsual application.

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

AndreKR
@AndreKR = I did not know whether DATEDIFF exist in POSTGRES or not. 3. Yes I do, why = does not concern you, and yes I'm sure
Roland
@Roland- Wow, what a prick. You were the one asking for help guy.
Scott Bailey
@Scott - Yes, agreed
Roland