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(DATE_SUB(curdate(),INTERVAL1MONTH),'%Y-%m')select*fromuserwhere DATE_FORMAT(pudate,'%Y%m')= DATE_FORMAT(CURDATE(),'%Y%m');select*fromuserwhere WEEKOFYEAR(FROM_UNIXTIME(pudate,'%y-%m-%d'))= WEEKOFYEAR(now())select*fromuserwhereMONTH(FROM_UNIXTIME(pudate,'%y-%m-%d'))=MONTH(now())select*fromuserwhereYEAR(FROM_UNIXTIME(pudate,'%y-%m-%d'))=YEAR(now())andMONTH(FROM_UNIXTIME(pudate,'%y-%m-%d'))=MONTH(now())select*fromuserwhere pudate between 上月最后一天 and 下月第一天
查询当前月份的数据
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(),interval6month)andnow();