Pieter888
Pieter888

Reputation: 4992

Selecting all records from one year ago till now

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?

Upvotes: 75

Views: 83478

Answers (4)

zzapper
zzapper

Reputation: 5043

To first of month a year ago

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

Upvotes: 1

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')

Upvotes: -5

Dimanenator I
Dimanenator I

Reputation: 121

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

Upvotes: 12

nos
nos

Reputation: 229088

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

Upvotes: 200

Related Questions