Selecting all records from one year ago till now

Mysql

Mysql Problem Overview


I have a table filled with a lot of rows and I need to select all the rows that are less than a year old till now.

The table (called orders) has a DateTime column named order_date, that's the field that determines when the order was placed.

How can I select all the records that have an order_date between now and a full year ago?

Mysql Solutions


Solution 1 - Mysql

select * 
from orders 
where order_date >= DATE_SUB(NOW(),INTERVAL 1 YEAR);

Solution 2 - Mysql

SELECT * FROM order WHERE order_date >= curdate() - interval 1 year;

Solution 3 - Mysql

To first of month a year ago

SELECT DATE_SUB(DATE_FORMAT(CURRENT_DATE,'%Y-%m-01'),INTERVAL 1 YEAR);

Solution 4 - Mysql

I hope it helps you:

select * 
from table 
where (order_date BETWEEN '2/15/2011 3:36:18 PM' AND '2/17/2011 9:00:00 PM')

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPieter888View Question on Stackoverflow
Solution 1 - MysqlnosView Answer on Stackoverflow
Solution 2 - MysqlDimanenator IView Answer on Stackoverflow
Solution 3 - MysqlzzapperView Answer on Stackoverflow
Solution 4 - MysqlSai Kalyan Kumar AkshinthalaView Answer on Stackoverflow