当前位置:网站首页>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
边栏推荐
- 面试集锦库
- DOS 功能调用
- 谢邀,人在工区,刚交代码,在下字节跳动实习生
- ~75 background
- Fdog series (I): think about it. It's better to write a chat software. Then start with the imitation QQ registration page.
- The 116 students spent three days reproducing the ByteDance internal real technology project
- Mongodb learning notes
- Activiti directory (III) deployment process and initiation process
- LeetCode 1020. Number of enclaves
- Activiti目录(一)重点介绍
猜你喜欢
Fdog series (V): use QT to imitate QQ to realize login interface to main interface, function chapter.
~73 other text styles
The daemon thread starts redis and modifies the configuration file
姚班智班齐上阵,竞赛高手聚一堂,这是什么神仙编程大赛?
Redis standalone startup
MySQL日期函数
Which is more important for programming, practice or theory [there are some things recently, I don't have time to write an article, so I'll post an article on hydrology, and I'll fill in later]
Eight part essay that everyone likes
Solr new core
~76 sprite map
随机推荐
Shell_ 02_ Text three swordsman
登陆验证koa-passport中间件的简单使用
Only learning C can live up to expectations top5 S1E8 | S1E9: characters and strings & arithmetic operators
TypeScript基本操作
When it comes to Google i/o, this is how ByteDance is applied to flutter
亮相Google I/O,字节跳动是这样应用Flutter的
LeetCode 1984. Minimum difference in student scores
Error: case label `15 'not within a switch statement
LeetCode 1636. Sort the array in ascending order by frequency
~78 radial gradient
Install docker under windows10 (through Oracle VM VirtualBox)
Ce n'est qu'en apprenant que c est à la hauteur des attentes Top5 s1e8 | s1e9: caractères et chaînes & opérateurs arithmétiques
Shell_ 04_ Shell script
原型链继承
8086 CPU 内部结构
Train 100 pictures for 1 hour, and the style of the photos changes at will. There is a demo at the end of the article | siggraph 2021
The daemon thread starts redis and modifies the configuration file
唯有學C不負眾望 TOP5 S1E8|S1E9:字符和字符串&&算術運算符
谢邀,人在工区,刚交代码,在下字节跳动实习生
逻辑运算指令