当前位置:网站首页>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)
边栏推荐
- LabVIEW程序框图保存为图像
- flask-socketio实现websocket通信
- 禁用token及无感知更新token功能实现
- PHICOMM(斐讯)N1盒子 - Armbian5.77(Debian 9)配置自动连接WIFI无线网络
- Brute force recursion to dynamic programming 07 (516. Longest palindrome subsequence)
- ”QSqlDatabasePrivate::removeDatabase: connection ‘test-connect‘ is still in use“数据库多次打开报错
- 【SQL】—数据库操作、表操作
- initramfs详解----设备文件系统
- ssh(sshd)安全配置
- 使用VSCode中遇到的问题及解决办法
猜你喜欢
随机推荐
孩子坐不住就是不专注?猿辅导揭秘专注力的三大误区
【社媒营销】Facebook速推帖子如何运作?值得吗?
The cornerstone of high concurrency: multithreading, daemon threading, thread safety, thread synchronization, mutual exclusion lock, all in one article!...
Excel 如何比较两列字符串是否相同?
11-security认证.md
国标GB28181协议EasyGBS平台项目现场通知消息过多导致系统卡顿该如何解决?
vs studio 安装opencv 环境
VS Code 这么牛,再次印证了一句名言
开发JSP应用的基础知识
复杂多层布局的初级智能文本提示器
pytest:如何调用 pytest
Violent recursion to dynamic programming 06 (the sword refers to Offer II 095. Longest common subsequence)
不想当Window的Dialog不是一个好Modal,弹窗翻身记...
PHICOMM(斐讯)N1盒子 - Armbian5.77(Debian 9)基本配置
【面经】被虐了之后,我翻烂了equals源码,总结如下
Shell脚本乘法口诀等小实验
iNFTnews | 元宇宙的潜力:一股推动社会进步的力量
怎么做postgrsql主备?
二叉树的前序遍历、中序遍历、后序遍历和层序遍历
一个循环,两个循环问题的思考及复现