开发者

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_dat开发者_如何转开发e, 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?


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


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


To first of month a year ago

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜