tags:

views:

24

answers:

3

Hello All, Was wondering if someone could assist with some Postgres. I have a table which has a column called mydate which is a postgres date type. I want to do something like:

SELECT * FROM MyTable WHERE mydate > [Today-1year]

I've never used Postgres before and I'm sure I just need to know the name of some functions- I'll gladly look up the reference myself. Can anyone point me in the right direction?

Thanks!

+1  A: 

I think this will do it:

SELECT * FROM MyTable WHERE mydate > now()::date - 365;
Alex Howansky
Note that unlike `interval '1 year'`, this will not respect leap years. That may not be a concern of yours, but if it is, use my answer.
Paul Tomblin
now()::date == CURRENT_DATE
Milen A. Radev
+3  A: 
select * from mytable where mydate > now() - interval '1 year';
Paul Tomblin
+1  A: 

This should give you the current date minus 1 year:

select now() - interval '1 year';
coderaj