当前位置:网站首页>MySQL date function
MySQL date function
2022-07-06 17:01:00 【My71】
The database used in the following , May refer to Create exercise database
Return current date
function :CURDATE()
Instructions
SELECT CURDATE();Running results

Return current time
function :CURTIME()
Instructions
SELECT CURTIME();Running results

Returns the current date and time
function :NOW()
Instructions
SELECT NOW()Running results

Extract date value
function :DATE()
Instructions
SELECT DATE('2021-10-31 11:36:20')Running results

Extract the year value
function :YEAR()
Instructions
SELECT YEAR('2021-10-31 11:36:20')Running results

Extract the month value
function :MONTH()
Instructions
SELECT MONTH('2021-10-31 11:36:20')Running results

Extract the day value
function :DAY()
Instructions
SELECT DAY('2021-10-31 11:36:20')Running results

Extract the hour value
function :HOUR()
Instructions
SELECT HOUR('2021-10-31 11:36:20')Running results

Extract the minute value
function :MINUTE()
Instructions
SELECT MINUTE('2021-10-31 11:36:20')Running results

Extract second value
function :SECOND()
Instructions
SELECT SECOND('2021-10-31 11:36:20')Running results

Convert seconds into time
function :SEC_TO_TIME
Instructions
SELECT SEC_TO_TIME(3661)Running results

Turn the time into seconds
function :TIME_TO_SEC()
Instructions
SELECT TIME_TO_SEC('1:01:01')Running results

Calculation n Days after
function :ADDDATE(d,n)
explain :d Indicates the date ,n Days .
Instructions
SELECT ADDDATE('2021-10-31',10)Running results

Calculation n The day before
function :SUBDATE(d,n)
explain :d Indicates the date ,n Days .
Instructions
SELECT SUBDATE('2021-10-31 12:23:20',10)Running results

Calculation n Time in seconds
function :ADDTIME(t,n)
explain :t Time ,n Indicates the time interval , When n When it is an integer, it should be less than 60, It can also be expressed as a string .
Instructions
SELECT ADDTIME('2021-10-31 11:43:25',5),ADDTIME('2021-10-31 11:43:25','2:10:15')Running results

Calculation n Seconds ago
function :SUBTIME()
explain :t Time ,n Indicates the time interval , When n When it is an integer, it should be less than 60, It can also be expressed as a string .
Instructions
SELECT SUBTIME('2021-10-31 12:23:20',10),SUBTIME('2021-10-31 12:23:20','2:3:20')Running results

Calculate the date interval
function :DATEDIFF(d1,d2)
explain :d1 End date ,d2 Start date .
Instructions
SELECT DATEDIFF('2022-01-01','2021-10-31'),DATEDIFF('2021-10-31','2022-01-01')Running results

Calculate the time interval
function :TIMEDIFF(t1,t2)
explain :t1 It's the start time t2 End time
Instructions
SELECT TIMEDIFF('12:31:20','11:30:10')Running results

practice : Calculation xs The ages of all the people in the table
Instructions
select Student number , full name , Date of birth ,DATEDIFF(NOW(), Date of birth ) DIV 365 as Age from xs;Running results

边栏推荐
- 服务器端渲染(SSR)和客户端渲染(CSR)的区别
- 这116名学生,用3天时间复刻了字节跳动内部真实技术项目
- ~84 form supplement
- 原型链继承
- Alibaba cloud server docker installation mysql5.5
- 字节跳动多篇论文入选 CVPR 2021,精选干货都在这里了
- LeetCode 1640. Can I connect to form an array
- Activiti目录(五)驳回、重新发起、取消流程
- Go language uses the thrift protocol to realize the client and service end reports not enough arguments in call to oprot Writemessagebegin error resolution
- Many papers on ByteDance have been selected into CVPR 2021, and the selected dry goods are here
猜你喜欢

我走過最迷的路,是字節跳動程序員的腦回路

「博士毕业一年,我拿下 ACL Best Paper」

~74 JD top navigation bar exercise

MySQL optimization notes

Log4j2 major vulnerabilities and Solutions

ByteDance open source Gan model compression framework, saving up to 97.8% of computing power - iccv 2021

Solr standalone installation

这116名学生,用3天时间复刻了字节跳动内部真实技术项目

7-4 harmonic average

~85 transition
随机推荐
我走過最迷的路,是字節跳動程序員的腦回路
LeetCode 1640. Can I connect to form an array
How to configure hosts when setting up Eureka
Conception du système de thermomètre numérique DS18B20
LeetCode 1566. Repeat the pattern with length m at least k times
字节跳动2022校招研发提前批宣讲会,同学们最关心的10个问题
~84 form supplement
IDEA断点调试技巧,多张动图包教包会。
7-7 ring the stupid bell
Full record of ByteDance technology newcomer training: a guide to the new growth of school recruitment
The most lost road I have ever walked through is the brain circuit of ByteDance programmers
The QT program compiled on CentOS lacks a MySQL driven solution
8086 CPU 内部结构
[unsolved]7-14 calculation diagram
Shell_ 07_ Functions and regular expressions
唯有学C不负众望 TOP3 Demo练习
Activiti目录(五)驳回、重新发起、取消流程
Description of project structure configuration of idea
一个数10年工作经验的微服务架构老师的简历
7-12 inventory code base