mysql获取7天前数据,日期比较

select * from news where n_date>unix_timestamp( subdate( now() , interval 7
day ))order by n_click  desc

 

 

N天内记录

WHERE TO_DAYS(NOW()) - TO_DAYS(时间字段) <= N

今天的记录

where date(时间字段)=date(now())

where to_days(时间字段) = to_days(now());


查询一周:

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

你可能感兴趣的:(mysql获取7天前数据,日期比较)