Home >Database >Mysql Tutorial >What are the commonly used date and time functions in MySQL?
What are the commonly used date and time functions in MySQL? This article will introduce it to you, as shown in the figure below:
CURDATE(), CURRENT_DATE() returns the current date 'YYYY-MM-DD'
CURTIME(), CURRENT_TIME() returns the current time 'HH:MM:SS'
CURRENT_TIMESTAMP()
LOCALTIME()
NOW()
SYSDATE() returns the current date and time 'YYYY-MM-DD HH:MM:SS'
UNIX_TIMESTAMP( date) returns the number of seconds after Unix timestamp 1970-01-01 00:00:00. date can be a specified time, such as DATE string, DATETIME string, TIMESTAMP string, etc.
FROM_UNIXTIME(date) Converts unix timestamp to common format, which is the inverse function of UNIX_TIMESTAMP(date)
UTC_DATE() Returns the current UTC (Universal Standard Time) date value
UTC_TIME() returns the current UTC time value
--8 hours difference
MONTH(date ) Returns the month of date 1-12
MONTHNAME(date) Returns the full English name of the month of date
DAYNAME(date) Returns the day of the week corresponding to date The English name of a certain day
##TIME_TO_SEC(time) Returns the number of seconds to convert time
SEC_TO_TIME(sec) Returns the result of converting seconds to hours, minutes and seconds
DATE_ADD(date,INTERVAL expr type)
ADDDATE(date,INTERVAL expr type) Add operation to date
##DATE_SUB(date,INTERVAL expr type)
##DATEDIFF(date1, date2 ) Returns the day value of date1-date2
DATE_FORMAT(date,format) Returns the date value in the format specified by format
The above is the detailed content of What are the commonly used date and time functions in MySQL?. For more information, please follow other related articles on the PHP Chinese website!