SELECT CURDATE() AS 当前日期;
SELECT NOW() AS 当前时间;
SELECT QUARTER(CURDATE()) AS 当前季度;
SELECT DATE_FORMAT(CURDATE(),’%w’) AS 当前周几; —
SELECT DATE_FORMAT( SUBDATE(CURDATE(),DATE_FORMAT(CURDATE(),’%w’)-1), ‘%Y-%m-%d 00:00:00’) AS 本周一;
SELECT DATE_FORMAT( SUBDATE(CURDATE(),DATE_FORMAT(CURDATE(),’%w’)-7), ‘%Y-%m-%d 23:59:59’) AS 本周末;
SELECT DATE_FORMAT(CURDATE(),’%Y-%m-01 00:00:00′) AS 本月第一天;
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-3 month),’%Y-%m-‘),’01’) AS 本季度第一天;
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-1 month) AS 本季度最后一天;
SELECT * FROM report WHERE create_time BETWEEN DATE_FORMAT(CURDATE(),’%Y-%m-01 00:00:00′) AND NOW(); — 本月数据
SELECT * FROM report WHERE DATE_FORMAT(create_time, ‘%Y%m’) = DATE_FORMAT(CURDATE(), ‘%Y%m’); — 本月数据
select * from report where QUARTER(create_time)=QUARTER(now()); — 本季度数据
本文地址:https://blog.csdn.net/kk_gods/article/details/109000548