获取数据库当天,前一天的数据

来源:互联网 发布:淘宝超过发货时间 编辑:程序博客网 时间:2024/06/04 20:05

获取数据库中当天的数据

SELECT user_id,timestamp

FROM hoomic.t_mobile_sesion

where date_format(timestamp,'%Y%m%d') = date_format(now(), '%Y%m%d')

order by timestamp desc;

获取数据库中前一天的数据

方法一

SELECT * FROM hoomic.t_mobile_sesion where date_format(timestamp,'%Y%m%d') = date_format(adddate(now(),-1),'%Y%m%d') order by timestamp desc;

方法二

SELECT * FROM hoomic.t_mobile_sesion where date_format(timestamp,'%Y%m%d') = date_format(DATE_ADD(now(),INTERVAL -1 DAY),'%Y%m%d') order by timestamp desc;

 

0 0