当前位置:网站首页>Get the first/last day of the current week, month, quarter in MySQL
Get the first/last day of the current week, month, quarter in MySQL
2022-08-03 03:04:00 【Oranges are not oranges】
mysql 获取当年第一天的年月日格式:
SELECT DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1 DAY);
MySQLto get the current week、月、first day of the season/最后一天
The first day of the current week:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 1 DAY)
The last day of the current week:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) – 5 DAY)
The first day of the previous week:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 8 DAY)
前一周的最后一天:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 2 DAY)
The first day of the first two weeks:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 15 DAY)
The last day of the first two weeks:
select date_sub(curdate(),INTERVAL WEEKDAY(curdate()) + 9 DAY)
当前月的第一天:
SELECT concat(date_format(LAST_DAY(now()),’%Y-%m-’),’01′)
当前月的最后一天:
SELECT LAST_DAY(now())
The first day of the previous month:
SELECT concat(date_format(LAST_DAY(now() – interval 1 month),’%Y-%m-’),’01′)
The last day of the previous month:
SELECT LAST_DAY(now() – interval 1 month)
The first day of the first two months:
SELECT concat(date_format(LAST_DAY(now() – interval 2 month),’%Y-%m-’),’01′)
The last day of the first two months:
SELECT LAST_DAY(now() – interval 2 month)
The first day of the current season:
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-3 month),’%Y-%m-’),’01′)
The last day of the current season:
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-1 month)
The first day of the previous season:
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-6 month),’%Y-%m-’),’01′)
The last day of the previous season:
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-4 month)
The first day of the first two seasons:
select concat(date_format(LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-9 month),’%Y-%m-’),’01′)
The last day of the first two seasons:
select LAST_DAY(MAKEDATE(EXTRACT(YEAR FROM CURDATE()),1) + interval QUARTER(CURDATE())*3-7 month)
边栏推荐
猜你喜欢

vs studio 安装opencv 环境

Greenplum database failure analysis, can not listen to the port

initramfs详解----设备文件系统

visual studio 2012 为啥这么优秀

DJI内推码(2022年8月2日更新)

initramfs详解-----初识initramfs

Violence recursion to dynamic programming 08 (pony go chess)

南瓜科学新品上线 开辟益智玩具新世界

无法启动服务 错误 193 0xc1

The Sandbox 市场平台将上线 Isla Obscura 第五期 NFT 作品集
随机推荐
[@property enhancement in Objective-C language]
EasyGBS播放器优化:设备通道视频播放出现跳屏问题的修复
[Static type and dynamic type compile check and run check in Objective-C]
Incorrect datetime value: ‘2022-01-01‘ for function str_to_date
梅科尔工作室-14天华为培训三
【Objective-C语言中的@property增强】
常见钓鱼手法及防范
征集 |《新程序员》专访“Apache之父”Brian Behlendorf,你最想问什么?
韦东山 数码相框 项目学习(五)libjpeg-turbo的移植
【SQL】—数据库操作、表操作
暴力递归到动态规划 08(小马走象棋)
VS Code 这么牛,再次印证了一句名言
8-jwt工具类
44LVS负载均衡群集-NAT
【社媒营销】Facebook速推帖子如何运作?值得吗?
堆的应用:堆排序和TOP-K问题
MySQL里获取当前周、月、季的第一天/最后一天
Kubernetes:(八)调度约束和故障排查
开发JSP应用的基础知识
LVS负载均衡群集及部署LVS-NAT实验