当前位置:网站首页>Date time functions commonly used in MySQL
Date time functions commonly used in MySQL
2022-07-28 23:05:00 【bhegi_ seg】
Catalog
6. Formatting of date and time
1. date (date) function
** Return current date :**CURDATE(), CURRENT_DATE(), CURRENT_DATE

2. Time (time) function
** Return current time :**CURTIME(), CURRENT_TIME(), CURRENT_TIME

3. Date and time functions
** Returns the current date and time :**CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP, LOCALTIME(), LOCALTIME, LOCALTIMESTAMP(), LOCALTIMESTAMP, NOW(), SYSDATE()

NOW(), SYSDATE() The difference between :
NOW() Return to execute the current SQL The time of the statement :

SYSDATE() Returns the time when the current function is executed :

SYSDATE() You can pass in a parameter :fsp Indicates whether decimal second precision is included (0~6 position )

4. Date and time comparison

The output of the above three statements is the same .
Mysql You can directly compare the time size with the string in , As long as your date format is legal .
5. Date and time calculation
**DATE_ADD() function :** Date and time increase and decrease
Function INTERVAL A positive value after the parameter indicates that the date time increases , A negative value indicates that the date time decreases

**DATEDIFF() function :** Calculate the difference between two dates

**TIMEDIFF() function :** Calculate two time differences

6. Formatting of date and time
DATE_FORMAT(date,format) function :
Commonly used :DATE_FORMAT(SYSDATE(),‘%Y-%m-%d %H:%i:%s’)
%p:PM or AM;
%r:HH:mm:ss PM Form time ;
%W: Zhou , Zhou Ming , Such as Tuesday;
%w: Zhou ,0-6,0 It's Sunday ;
%j: The number of days in the year in which the current date is located ,3 position (001-366).




DATE_FORMAT(date,format) and STR_TO_DATE(str,format) function :
DATE_FORMAT(date,format): In the database date The data is formatted as String type
STR_TO_DATE(str,format): Converts the string in the specified time format into DATETIME Type value .str To work with format Keep the format consistent , Otherwise, an error will be reported .

The first return value is String type , The second return value is datetime type .
**YEAR() function :** Take the year of the date and time

边栏推荐
- 【物理应用】水下浮动风力涡轮机的尾流诱导动态模拟风场附matlab代码
- Mspba [anomaly detection: representation_based]
- Torch.fft.fft 2. () error reporting problem solution
- Summary of common formula notes for solving problems in Higher Mathematics
- 轮子六:QSerialPort 串口数据 收发
- WebApplicationType#deduceFromClasspath
- [copy] Internet terms, abbreviations, abbreviations
- LTE cell search process and sch/bch design
- Sqlilabs-3 (entry notes)
- Submission records of frontiers Publishing House (with status changes)
猜你喜欢

Improvement 17 of yolov5: cnn+transformer -- integrating bottleneck transformers

【物理应用】大气吸收损耗附matlab代码

定了!哪吒S全系产品将于7月31日上市发售

Record a question about the order of trigonometric function exchange integrals

《Robust and Communication-Efficient Federated Learning From Non-i.i.d. Data》论文阅读

Target detection notes fast r-cnn

Reading of "robust and communication efficient federated learning from non-i.i.d. data"

LTE cell search process and sch/bch design

NPM run dev, automatically open the browser after running the project

Thesis reading (2) - vggnet of classification
随机推荐
美国FCC提供16亿美元资助本国运营商移除华为和中兴设备
console.log()控制台显示...解决办法
Sqlilabs-3 (entry notes)
Cglib create proxy
Summary of C language learning content
【复制】互联网术语、简称、缩写
软件测试工具fiddler postman jmeter charlse核心功能总结
OSV-q The size of tensor a (3) must match the size of tensor b (320) at non-singleton dimension 3
Draem+sspcab [anomaly detection: block]
投资1450亿欧元!欧盟17国宣布联合发展半导体技术
Evaluation index of anomaly detection: rocauc et al. [tips]
Thesis reading (0) - alexnet of classification
弹框遮罩层「建议收藏」
Paper reading: deep forest / deep forest /gcforest
Thesis reading (3) - googlenet of classification
leetcode 199. 二叉树的右视图
希捷发布全新RISC-V架构处理器:机械硬盘相关性能暴涨3倍
业界首创云原生安全检测双模型!安全狗重磅报告亮相数字中国建设峰会
Symbol symbol type
Summary of the problem that MathType formula does not correspond in word