SQL-query everything from last month

Post Reply
Peter_w
Posts: 28
Joined: Tue Aug 19, 2008 9:28 am

SQL-query everything from last month

Post by Peter_w »

Hi,

How do I make a query to get everything from 1 month ago until now?

thanks.
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: SQL-query everything from last month

Post by chris »

You can add some special functions,
but they depend on what type of Database Management System (DBMS) you use.
For mysql:

Code: Select all

SELECT * FROM table WHERE datefield > DATE_SUB(NOW(), INTERVAL 1 MONTH);
for SQL server:

Code: Select all

SELECT * FROM table WHERE datefield > DATEADD(m, -1, GETDATE());
Not sure how it is in PostgreSQL and oracle,
but I'm sure it something similar.
Post Reply