mysql查询前n天的数据

2017-10-18  本文已影响0人  simplehu

假设数据表table中有个字段modifytime的类型为datetime类型或者TIMESTAMP类型

查询当天的数据

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

查询前n天的数据

select * from table where to_days(now()) – to_days(modifytime) <= n;

假设数据表汇总有个字段modifytime的类型为int(5)类型,则:

查询当天的数据

select * from table where date_format(from_UNIXTIME(modifytime),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d');

select * from table where to_days(date_format(from_UNIXTIME(modifytime),'%Y-%m-%d')) = to_days(now());

参考于:http://www.jb51.net/article/51597.htm

上一篇 下一篇

猜你喜欢

热点阅读