mysql获取日、周、月、年记录

-- 今日记录
select * from buy where TO_DAYS(time) = TO_DAYS(NOW())
-- 本月记录
SELECT * FROM buy  WHERE DATE_FORMAT( time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
-- 本周记录
SELECT * FROM buy  WHERE YEARWEEK(date_format(time,'%Y-%m-%d'),1) = YEARWEEK(now(),1);
-- 年记录
SELECT * FROM buy  WHERE DATE_FORMAT( time, '%Y' ) = DATE_FORMAT( CURDATE( ) , '%Y' )

 

你可能感兴趣的:(网站建设——问卷调查网站)