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

获取数据库中当天的数据

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;

 

你可能感兴趣的:(CodeIgniter,PHP)