Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql select records greater than 3 months

Tags:

I am trying to write a query to select all records from users table where User_DateCreated (datetime field) is >= 3 months from today.

Any ideas?

like image 970
fire Avatar asked May 04 '10 14:05

fire


People also ask

How do I get last 3 months records in SQL?

In SQL Server, you can use the DATEADD() function to get last 3 months (or n months) records.

How do I get last 6 months data in SQL?

Instead of approximating the "current" date by selecting the MAX(date) the code could reference CAST(GETDATE() as DATE) to access the system datetime and cast it as type DATE. where [date] > dateadd(month, -6, cast(getdate() as date));

How do I select a date range in MySQL?

If you need to select rows from a MySQL database' table in a date range, you need to use a command like this: SELECT * FROM table WHERE date_column >= '2014-01-01' AND date_column <= '2015-01-01'; Of course you need to change: table.


1 Answers

SELECT  * FROM    users WHERE   user_datecreated >= NOW() - INTERVAL 3 MONTH 
like image 65
Quassnoi Avatar answered Oct 22 '22 17:10

Quassnoi