Date-type single-row functions in MySQL: SELECT CURDATE() FROM DUAL; SELECT CURRENT_DATE() FROM DUAL; -----------------------------------(dividing line)------------------------------------ SELECT CURTIME() FROM DUAL; SELECT CURRENT_TIME() FROM DUAL; -----------------------------------(dividing line)------------------------------------ SELECT NOW() FROM DUAL; SELECT LOCALTIME() FROM DUAL; -----------------------------------(dividing line)------------------------------------ SELECT YEAR(CURDATE()), MONTH(CURDATE()), DAY(CURDATE()) FROM DUAL; SELECT HOUR(CURTIME()),MINUTE(NOW()),SECOND(NOW()) FROM DUAL; Note: The functions here, and the contents in the brackets come from the functions mentioned above. -----------------------------------(dividing line)------------------------------------ SELECT WEEK(NOW()) FROM DUAL; SELECT WEEKOFYEAR(CURDATE()) FROM DUAL; -----------------------------------(dividing line)------------------------------------ SELECT DAYOFWEEK(NOW()) FROM DUAL; The code compilation results are as follows: Explain that it is Thursday -----------------------------------(dividing line)------------------------------------ SELECT WEEKDAY(NOW()) FROM DUAL; The code compilation results are as follows: Explain that it is Thursday -----------------------------------(dividing line)------------------------------------ 8. SELECT DAYNAME(CURDATE()),DAYNAME('2020-09-06') #implicit conversion FROM DUAL; The code compilation results are as follows: Remark: Convert string to date (parse) (explicit conversion) SELECT STR_TO_DATE('09/01/2009','%m/%d/%Y') FROM DUAL; The code compilation results are as follows: Convert string to date (parse) (explicit conversion) SELECT STR_TO_DATE('20140422154706','%Y%m%d%H%i%s') FROM DUAL; The code compilation results are as follows: Convert string to date (parse) (explicit conversion) SELECT STR_TO_DATE('2014-04-22 15:47:06','%Y-%m-%d %H:%i:%s') FROM DUAL; The code compilation results are as follows: -----------------------------------(dividing line)------------------------------------ 9. SELECT MONTHNAME(NOW()) FROM DUAL; -----------------------------------(dividing line)------------------------------------ SELECT DATEDIFF('2021-03-06','2021-06-09') FROM DUAL; Note: The returned value is the number of days between the two dates = date1-date2. If date1 is before date2, the returned value is a negative value. SELECT TIMEDIFF('2019-06-06 18:23:06','2019-08-06 10:36:45') FROM DUAL; Note: The returned value is the difference between the two times [hours: minutes: seconds] = time1-time2. If time1 is before time2, the value returned is a negative value. The above is the details of the date type single-row function in MySQL. For more information about MySQL single-row functions, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Example code of javascript select all/unselect all operation in html
>>: Two ways to implement text stroke in CSS3 (summary)
Because the router at home forced to reduce the b...
Table of contents DOM node Element node: Text nod...
During project development, our database data is ...
Table of contents Function call optimization Func...
Preface This article mainly explains how to imple...
Table of contents 1. What is a custom instruction...
Referring to the online information, I used cmake...
Table of contents 1. Communication between father...
The mini program implements a complete shopping c...
1. Description In MySQL, when we need to get the ...
When doing a project, it is inevitable to encount...
There are two ways: 1. Service method Check the f...
The tutorial for installing OpenStack Ussuri with...
Use HTML to create complex tables. Complex tables...
The effect diagram is as follows: <!DOCTYPE ht...