MySQL Date and Time Functions
This page lists the date and time functions that can be used to manipulate temporal values in MySQL.
-
ADDDATE
The MySQLADDDATE()
function adds a date/time interval to a date or datetime value and returns the result. -
ADDTIME
The MySQLADDTIME()
function adds a specified time value to another specified time and returns the result. -
CONVERT_TZ
The MySQLCONVERT_TZ()
function converts a time in one time zone to the time in another time zone. -
CURDATE
The MySQLCURDATE()
function returns the system’s current date inYYYY-MM-DD
orYYYYMMDD
format. -
CURRENT_DATE
The MySQLCURRENT_DATE()
function returns the system’s current date inYYYY-MM-DD
orYYYYMMDD
format. -
CURRENT_TIME
The MySQLCURRENT_TIME()
function returns the current time of the system inhh:mm:ss
orhhmmss
format. -
CURRENT_TIMESTAMP
The MySQLCURRENT_TIMESTAMP()
function returns the current date and time in theYYYY-MM-DD hh:mm:ss
orYYYYMMDDhhmmss
format. -
CURTIME
The MySQLCURTIME()
function returns the current time of the system inhh:mm:ss
orhhmmss
format. -
DATE
The MySQLDATE()
function extracts and returns the date part from a datetime value. -
DATE_ADD
The MySQLDATE_ADD()
function adds the specified interval to the specified date/time and returns the result. -
DATE_FORMAT
The MySQLDATE_FORMAT()
function formats a date or datetime value into a specific pattern. -
DATE_SUB
The MySQLDATE_SUB()
function subtracts a date or time interval from the specified date or datetime and returns the result. -
DATEDIFF
The MySQLDATEDIFF()
function returns the number of days between two date values. -
DAY
The MySQLDAY()
function returns a number representing the day of the month in a datetime expression. -
DAYNAME
The MySQLDAYNAME()
function returns the weekday name for a given date. -
DAYOFMONTH
The MySQLDAYOFMONTH()
function returns a number representing the day of the month in a datetime expression. -
DAYOFWEEK
The MySQLDAYOFWEEK()
function returns the weekday index of a given date. -
DAYOFYEAR
The MySQLDAYOFYEAR()
function returns a number from1
to366
representing the day of the year. -
EXTRACT
The MySQLEXTRACT()
function extracts and returns the specified part from the specified date/time. -
FROM_DAYS
The MySQLFROM_DAYS()
function converts the specified number of days to a date and returns it. -
FROM_UNIXTIME
The MySQLFROM_UNIXTIME()
function will convertunix_timestamp
to a datetime and formats it as a string if a format string is specified. -
GET_FORMAT
The MySQLGET_FORMAT()
function returns a format string according to arguments. -
HOUR
The MySQLHOUR()
function extracts and returns the hour portion of a time. -
LAST_DAY
The MySQLLAST_DAY()
function returns the last day of the month for the specified date or datetime. -
LOCALTIME
The MySQLLOCALTIME()
function returns the current date and time in theYYYY-MM-DD hh:mm:ss
orYYYYMMDDhhmmss
format. -
LOCALTIMESTAMP
The MySQLLOCALTIMESTAMP()
function returns the current date and time in theYYYY-MM-DD hh:mm:ss
orYYYYMMDDhhmmss
format. -
MAKEDATE
The MySQLMAKEDATE()
function creates and returns a date based on the year and the number of days in the year. -
MAKETIME
The MySQLMAKETIME()
function creates a time based on the specified hour, minute, and second to and returns it. -
MICROSECOND
The MySQLMICROSECOND()
function extracts the microsecond part of a time or datetime and return it as a number. -
MINUTE
The MySQLMINUTE()
function extracts and returns the minute part of a time. -
MONTH
The MySQLMONTH()
function extracts the month part of a date and return it as a number. -
MONTHNAME
The MySQLMONTHNAME()
function returns the name of the month for a given date. -
NOW
The MySQLNOW()
function returns the current date and time inYYYY-MM-DD hh:mm:ss
orYYYYMMDDhhmmss
format. -
PERIOD_ADD
The MySQLPERIOD_ADD()
function adds the specified number of months to the specified year-month and returns the result as year-month. -
PERIOD_DIFF
The MySQLPERIOD_DIFF()
function returns the number of months between two periods specified by year and month. -
QUARTER
The MySQLQUARTER()
function returns the quarter of the year for a specified date. -
SEC_TO_TIME
The MySQLSEC_TO_TIME()
function converts the specified number of seconds to a time value inHH:MM:SS
format. -
SECOND
The MySQLSECOND()
function extracts and returns the second part of a time. -
STR_TO_DATE
The MySQLSTR_TO_DATE()
function converts the specified string to date/time according to the specified format. -
SUBDATE
The MySQLSUBDATE()
function subtracts a date or time interval from the specified date or datetime and returns the result. -
SUBTIME
The MySQLSUBTIME()
function subtracts a specified time interval from another specified time and returns the result. -
SYSDATE
The MySQLSYSDATE()
function returns the current time and date in theYYYY-MM-DD hh:mm:ss
format. -
TIME
The MySQLTIME()
function extracts the time part from a time or datetime and return it. -
TIME_FORMAT
The MySQLTIME_FORMAT()
function formats the time according to the specified format. -
TIME_TO_SEC
The MySQLTIME_TO_SEC()
function converts the specified time value to the number of seconds. -
TIMEDIFF
The MySQLTIMEDIFF()
function returns the difference between two time values. -
TIMESTAMP
The MySQLTIMESTAMP()
function sum all arguments and return the result as a datetime value. -
TIMESTAMPADD
The MySQLTIMESTAMPADD()
function adds the specified interval to a datetime value and returns the result. -
TIMESTAMPDIFF
The MySQLTIMESTAMPDIFF()
function returns the time interval between two datetimes. -
TO_DAYS
The MySQLTO_DAYS()
function converts the specified date to the number of days since year 0 and returns the result. -
TO_SECONDS
The MySQLTO_SECONDS()
function converts the specified date/datetime to seconds from 0 years and returns the result. -
UNIX_TIMESTAMP
The MySQLUNIX_TIMESTAMP()
function converts the specified date/datetime to a UNIX timestamp value. -
UTC_DATE
The MySQLUTC_DATE()
function returns the current UTC date. -
UTC_TIME
The MySQLUTC_TIME()
function returns the current UTC time. -
UTC_TIMESTAMP
The MySQLUTC_TIMESTAMP()
function returns the current UTC date and time. -
WEEK
The MySQLWEEK()
function returns the week number in the current year for the gaven date. -
WEEKDAY
The MySQLWEEKDAY()
function returns the weekday index for a given date. -
WEEKOFYEAR
The MySQLWEEKOFYEAR()
function returns the week number in the current year for the gaven date. -
YEAR
The MySQLYEAR()
function extracts the year part of a date and return it as a number. -
YEARWEEK
The MySQLYEARWEEK()
function returns a number representing the year and week of the given date.