MySQL DATE Functions

MySQL provides a comprehensive set of date and time functions for manipulating and extracting information from date and time values. These functions are essential for various data manipulation tasks, including retrieving current dates and times, calculating date differences, formatting date and time values, and extracting specific components from date and time expressions.

Here’s a breakdown of some of the key MySQL date functions:

FunctionDescription
NOWReturns the current date and time.
DATE_FORMATFormats a date as specified by the format string.
DATEDIFFReturns the difference in days between two dates.
CURDATEReturns the current date.
ADDDATEAdds a specified interval to a date.
ADDTIMEAdds a specified time to a datetime value.
CONVERT_TZConverts a datetime value from one time zone to another.
CURRENT_DATEReturns the current date.
CURRENT_TIMEReturns the current time.
CURRENT_TIMESTAMPReturns the current date and time in the YYYY-MM-DD HH:MM:SS format.
CURTIMEReturns the current time in the HH:MM:SS format.
DATEExtracts the date part from a datetime or timestamp value.
DATE_ADDAdds a time interval to a date.
DATE_SUBSubtracts a time interval from a date.
DAYReturns the day of the month for a given date.
EXTRACTExtracts a specific part of a date (e.g., year, month, day).
DAYNAMEReturns the name of the day of the week for a given date.
HOURReturns the hour from a given time.
LAST_DAYReturns the last day of the month for a given date.
MINUTEReturns the minute of the hour for a datetime value.
MONTHReturns the month of the year for a date.
SECONDReturns the seconds component of a datetime value.
SYSDATEReturns the current date and time as a timestamp.
TIMEExtracts the time portion from a datetime value.
TIMESTAMPCreates a timestamp from a combination of date and time values.
WEEKRetrieves the week number of the year for a date.
WEEKDAYReturns the day of the week index for a date (0-6, Sunday-Saturday).
YEARReturns the year component of a date.

MySQL’s DATE functions provide a powerful and versatile set of tools for working with dates and times in your database applications. These functions can be used to manipulate date values, extract specific date components, compare dates, perform date arithmetic, and format dates for display.