MySQL裡獲取當前week、month、quarter的start_date/end_date 當前week的第一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 1 DAY) 當前week的最後一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) - 5 DAY) 前一week的第一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 8 DAY) 前一week的最後一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 2 DAY) 前兩week的第一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 15 DAY) 前兩week的最後一天: select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 9 DAY) 當前month的第一天: SELECT concat(date_format(LAST_DAY(now()),'%Y-%m-'),'01') 當前month的最後一天: SELECT LAST_DAY(now()) 前一month的第一天: SELECT concat(date_format(LAST_DAY(now() - interval 1 month),'%Y-%m-'),'01') 前一month的最後一天: SELECT LAST_DAY(now() - interval 1 month) 前兩month的第一天: SELECT concat(date_format(LAST_DAY(now() - interval 2 month),'%Y-%m-'),'01') 前兩month的最後一天: SELECT LAST_DAY(now() - interval 2 month) 當前quarter的第一天: select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-3 month),'%Y-%m-'),'01') 當前quarter的最後一天: select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-1 month) 前一quarter的第一天: select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-6 month),'%Y-%m-'),'01') 前一quarter的最後一天: select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-4 month) 前兩quarter的第一天: select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-9 month),'%Y-%m-'),'01') 前兩quarter的最後一天: select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-7 month)