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)
Recommended Docker learning materials: https://ww...
I have never been able to figure out whether the ...
This article example shares the specific code of ...
This article example shares the specific code of ...
HTML5 adds more semantic tags, such as header, fo...
1. Requirements description Display the delete ic...
This article shares the specific code of JavaScri...
Table of contents $nextTick() $forceUpdate() $set...
This article shares the specific steps of install...
When installing Docker on Windows 10, after selec...
apache: create virtual host based on port Take cr...
Preface Usually, a "paging" strategy is...
Table of contents Write in front Business code us...
Mysql join query 1. Basic concepts Connect each r...
When processing batch updates of certain data, if...