当前位置:网站首页>mysql获得时间
mysql获得时间
2022-07-05 13:17:00 【玲珑·】
#当年第一天:
SELECT DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1 DAY);
#当年最后一天:
SELECT concat(YEAR(now()),'-12-31');
#当前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);
边栏推荐
- A specific example of ABAP type and EDM type mapping in SAP segw transaction code
- Write API documents first or code first?
- Yyds dry goods inventory # solve the real problem of famous enterprises: move the round table
- 【Hot100】34. Find the first and last positions of elements in a sorted array
- Write macro with word
- Realize the addition of all numbers between 1 and number
- Shu tianmeng map × Weiyan technology - Dream map database circle of friends + 1
- Rocky基础知识1
- 从外卖点单浅谈伪需求
- 百日完成国产数据库opengausss的开源任务--openGuass极简版3.0.0安装教程
猜你喜欢
Navigation property and entityset usage in SAP segw transaction code
逆波兰表达式
RHCSA9
Principle and configuration of RSTP protocol
Hiengine: comparable to the local cloud native memory database engine
Pandora IOT development board learning (HAL Library) - Experiment 7 window watchdog experiment (learning notes)
leetcode:221. Maximum square [essence of DP state transition]
A detailed explanation of ASCII code, Unicode and UTF-8
峰会回顾|保旺达-合规和安全双驱动的数据安全整体防护体系
Flutter 绘制波浪移动动画效果,曲线和折线图
随机推荐
The solution of outputting 64 bits from printf format%lld of cross platform (32bit and 64bit)
go map
聊聊异步编程的 7 种实现方式
Detailed explanation of navigation component of openharmony application development
Lb10s-asemi rectifier bridge lb10s
[deep learning paper notes] hnf-netv2 for segmentation of brain tumors using multimodal MR imaging
Go string operation
实现 1~number 之间,所有数字的加和
Realize the addition of all numbers between 1 and number
Introduction to sap ui5 dynamicpage control
JS to determine whether an element exists in the array (four methods)
Write macro with word
OpenHarmony应用开发之Navigation组件详解
【每日一题】1200. 最小绝对差
前缀、中缀、后缀表达式「建议收藏」
uni-app开发语音识别app,讲究的就是简单快速。
Natural language processing from Xiaobai to proficient (4): using machine learning to classify Chinese email content
LB10S-ASEMI整流桥LB10S
DataPipeline双料入选中国信通院2022数智化图谱、数据库发展报告
解决 UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xa2 in position 107