MySQL Date Functions
SQL includes three functions that return information about the current date, current time, or both. CURRENT_DATE returns the current date; CURRENT_TIME returns the current time; and CURRENT_TIMESTAMP returns both the current date and the current time.
| Function | Description |
|---|---|
| ADDDATE | Returns a date after a certain time/date interval has been added |
| ADDTIME | Returns a time/datetime after a certain time interval has been added |
| CURDATE | Returns the current date |
| CURRENT_DATE | Returns the current date |
| CURRENT_TIME | Returns the current time |
| CURRENT_TIMESTAMP | Returns the current date and time |
| CURTIME | Returns the current time |
| DATE | Extracts the date value from a date or datetime expression |
| DATEDIFF | Returns the difference in days between two date values |
| DATE_ADD | Returns a date after a certain time/date interval has been added |
| DATE_FORMAT | Formats a date as specified by a format mask |
| DATE_SUB | Returns a date after a certain time/date interval has been subtracted |
| DAY | Returns the day portion of a date value |
| DAYNAME | Returns the weekday name for a date |
| DAYOFMONTH | Returns the day portion of a date value |
| DAYOFWEEK | Returns the weekday index for a date value |
| DAYOFYEAR | Returns the day of the year for a date value |
| EXTRACT | Extracts parts from a date |
| FROM_DAYS | Returns a date value from a numeric representation of the day |
| HOUR | Returns the hour portion of a date value |
| LAST_DAY | Returns the last day of the month for a given date |
| LOCALTIME | Returns the current date and time |
| LOCALTIMESTAMP | Returns the current date and time |
| MAKEDATE | Returns the date for a certain year and day-of-year value |
| MAKETIME | Returns the time for a certain hour, minute, second combination |
| MICROSECOND | Returns the microsecond portion of a date value |
| MINUTE | Returns the minute portion of a date value |
| MONTH | Returns the month portion of a date value |
| MONTHNAME | Returns the full month name for a date |
| NOW | Returns the current date and time |
| PERIOD_ADD | Takes a period and adds a specified number of months to it |
| PERIOD_DIFF | Returns the difference in months between two periods |
| QUARTER | Returns the quarter portion of a date value |
| SECOND | Returns the second portion of a date value |
| SEC_TO_TIME | Converts numeric seconds into a time value |
| STR_TO_DATE | Takes a string and returns a date specified by a format mask |
| SUBDATE | Returns a date after which a certain time/date interval has been subtracted |
| SUBTIME | Returns a time/datetime value after a certain time interval has been subtracted |
| SYSDATE | Returns the current date and time |
| TIME | Extracts the time value from a time/datetime expression |
| TIME_FORMAT | Formats a time as specified by a format mask |
| TIME_TO_SEC | Converts a time value into numeric seconds |
| TIMEDIFF | Returns the difference between two time/datetime values |
| TIMESTAMP | Converts an expression to a datetime value and if specified adds an optional time interval to the value |
| TO_DAYS | Converts a date into numeric days |
| WEEK | Returns the week portion of a date value |
| WEEKDAY | Returns the weekday index for a date value |
| WEEKOFYEAR | Returns the week of the year for a date value |
| YEAR | Returns the year portion of a date value |
| YEARWEEK | Returns the year and week for a date value |