当前位置:网站首页>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

边栏推荐
- PCA学习
- Submission records of frontiers Publishing House (with status changes)
- 无代码开发平台通讯录导出入门教程
- 投资500亿元!中芯京城正式注册成立!
- Console.log() console display... Solution
- LeetCode练习3——回文数
- 《MySQL数据库进阶实战》读后感(SQL 小虚竹)
- Thesis reading (3) - googlenet of classification
- Summary of core functions of software testing tool Fiddler postman JMeter charlse
- [database]
猜你喜欢

console.log()控制台显示...解决办法

无代码开发平台通讯录导出入门教程
![Mspba [anomaly detection: representation_based]](/img/95/1f7390ec024a2865acb9e9a41100b1.png)
Mspba [anomaly detection: representation_based]

OSV_ q AttributeError: ‘numpy. ndarray‘ object has no attribute ‘clone‘

Sqlilabs-1 (breakthrough record)

Shell script foundation - shell operation principle + variable and array definitions

【雷达】基于核聚类实现雷达信号在线分选附matlab代码

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

can‘t convert cuda:0 device type tensor to numpy. Use Tensor. cpu() to copy the tensor to host memory

Nacos配置热更新的4种方式、读取项目配置文件的多种方式,@value,@RefreshScope,@NacosConfigurationProperties
随机推荐
cnpm安装步骤
The US FCC provided us $1.6 billion to support domestic operators to remove Huawei and ZTE equipment
leetcode 199. 二叉树的右视图
LTE cell search process and sch/bch design
18 diagrams, intuitive understanding of neural networks, manifolds and topologies
Evaluation index of anomaly detection: rocauc et al. [tips]
LeetCode练习3——回文数
pgbench基准测试《postgresql》
Mspba [anomaly detection: representation_based]
Thesis reading (0) - alexnet of classification
OSV_ q Expected all tensors to be on the same device, but found at least two devices, cuda:0
Invest 145billion euros! EU 17 countries announce joint development of semiconductor technology
(important) first knowledge of C language -- function
定了!哪吒S全系产品将于7月31日上市发售
Target detection notes fast r-cnn
can‘t convert cuda:0 device type tensor to numpy. Use Tensor. cpu() to copy the tensor to host memory
Lenovo r9000p installation matlab2018a+cuda10.0 compilation
Anaconda environment installation skimage package
OSV-q ValueError: axes don‘t match array
Morphology of image