1. 程式人生 > >MYSQL查詢通過date型別的欄位查詢一段時間記錄

MYSQL查詢通過date型別的欄位查詢一段時間記錄

select * from wap_content where week(created_at) = week(now)

 

如果你要嚴格要求是某一年的,那可以這樣

 

查詢一天:

 

select * from table where to_days(column_time) = to_days(now());

select * from table where date(column_time) = curdate();

 

查詢一週:

 

select * from table where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(column_time);

 

查詢一個月:

 

select * from table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <= date(column_time);

 

查詢某幾天:

關鍵字between 等同於 datetime >= 2010-02-02 00:00:00' and datetime <=  '2010-02-15 00:00:00';

select * from table where datetime between '2010-02-02 00:00:00' and '2010-02-15 00:00:00';