查询当前这周的数据
SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now()); 查询上周的数据 SELECT name,submittime FROM enterprise WHERE YEARWEEK(date_format(submittime,'%Y-%m-%d')) = YEARWEEK(now())-1; 查询当前月份的数据 select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(now(),'%Y-%m') 查询距离当前现在6个月的数据 select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now(); 查询上个月的数据 select name,submittime from enterprise where date_format(submittime,'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m') e.g.查询上周的数据,SELECT visitname,create_time FROM g2park_vip_info WHERE YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now())-1;
这个now()是2018-08-09,查询的是7.29到8.4(上周)的数据
SELECT DATE_ADD(DATE_FORMAT(now(),'%Y-%m-%d'),INTERVAL 0-DAYOFWEEK(now()) day);-- 上周最后一天
SELECT DATE_ADD(DATE_FORMAT(now(),'%Y-%m-%d'),INTERVAL 0-DAYOFMONTH(now()) day);-- 上周最后一天