Page 1 of 1

SQL-query everything from last month

Posted: Fri Feb 26, 2016 12:49 pm
by Peter_w
Hi,

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

thanks.

Re: SQL-query everything from last month

Posted: Fri Feb 26, 2016 1:12 pm
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.