MySQL当月第一天

发布时间: 2023-11-21 12:33 阅读: 文章来源:1MUMB3886PS
导语

部分实用的日期函数组合查询。

查询:本周,本月,本季度,本年的第一天和最后一天#查询本周第一天select DATE_SUB(CURDATE(),INTERVAL WEEKDAY(CURDATE()) DAY) AS TIME;#查询本周的最后一天select DATE_SUB(CURDATE(),INTERVAL WEEKDAY(CURDATE())-6 DAY) AS TIME;#查询本月的第一天select DATE_SUB(CURDATE(),INTERVAL DAY(CURDATE())-1 DAY) AS TIME;#查询本月的最后一天select LAST_DAY(CURDATE()) AS TIME;#当前quarter的第一天:select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROMCURDATE()),1) + interval QUARTER(CURDATE())*3-3 month),‘%Y-%m-‘),‘01‘); #当前quarter的最后一天:select LAST_DAY(MAKEDATE(EXTRACT(YEARFROM CURDATE()),1) + interval QUARTER(CURDATE())*3-1 month);#当年第一天:select DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1 DAY); #当年最后一天:select concat(YEAR(now()),‘-12-31‘);
•••展开全文
相关文章