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)
1. DNS server concept Communication on the Intern...
Introduction: Regarding MySQL database specificat...
The mysql on the server is installed with version...
answer from stackflow: Simply <br> is suffic...
Table of contents 1. Example scenario 1.1. Set th...
Table of contents Preface Install the graphics dr...
1 Introduction Thread technology was proposed as ...
Linux File System Common hard disks are shown in ...
CSS3 syntax: (1rem = 100px for a 750px design) @m...
This article introduces Nginx from compilation an...
1. Online Text Generator BlindTextGenerator: For ...
This article shares the specific code of Vue to i...
Since we are going to upload pictures, the first ...
This article example shares the specific code of ...
If a form field in a form is set to disabled, the ...