字段column_time的格式为时间格式
from_unixtime将时间戳转换为时间格式 *做个记号,之前纠结了半天
select * from wap_content where week(column_time) = 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 1 MONTH) <= date(column_time);
========================附
今天
select * from 表名 where to_days(时间字段名) = to_days(now());
昨天
Select * FROM 表名 Where TO_DAYS( NOW( ) ) – TO_DAYS( 时间字段名) <= 1
7天
Select * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名)
近30天
Select * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名)
本月
Select * FROM 表名 Where DATE_FORMAT( 时间字段名, ‘%Y%m’ ) = DATE_FORMAT( CURDATE( ) , ‘%Y%m’ )
上一月
Select * FROM 表名 Where PERIOD_DIFF( date_format( now( ) , ‘%Y%m’ ) , date_format( 时间字段名, ‘%Y%m’ ) ) =1