Quick Reference
This is a quick reference list of MySQL date functions and how they are used to work with databases.
- SQL – MySQL ADDDATE() FunctionThe MySQL ADDDATE() function adds a time/date interval to a date and then returns the date.
- SQL – MySQL ADDTIME() FunctionThe MySQL ADDTIME() function adds a time interval to a time/datetime and then returns the time/datetime.
- SQL – MySQL CURDATE() FunctionThe MySQL CURDATE() function returns the current date as “YYYY-MM-DD” (string) or as YYYYMMDD (numeric).
- SQL – MySQL CURRENT_DATE() FunctionThe MySQL CURRENT_DATE() function returns the current date as “YYYY-MM-DD” (string) or as YYYYMMDD (numeric).
- SQL – MySQL CURRENT_TIME() FunctionThe MySQL CURRENT_TIME() function returns the current time as “HH-MM-SS” (string) or as HHMMSS.uuuuuu (numeric).
- SQL – MySQL CURRENT_TIMESTAMP() FunctionThe MySQL CURRENT_TIMESTAMP() function returns the current date and time as “YYYY-MM-DD HH-MM-SS” (string) or as YYYYMMDDHHMMSS.uuuuuu (numeric).
- SQL – MySQL CURTIME() FunctionThe MySQL CURTIME() function returns the current time as “HH-MM-SS” (string) or as HHMMSS.uuuuuu (numeric).
- SQL – MySQL DATE() FunctionThe MySQL DATE() function extracts the date part from a datetime expression.
- SQL – MySQL DATEDIFF() FunctionThe MySQL DATEDIFF() function returns the number of days between two date values.
- SQL – MySQL DATE_ADD() FunctionThe MySQL DATE_ADD() function adds a time/date interval to a date and then returns the date.
- SQL – MySQL DATE_FORMAT() FunctionThe MySQL DATE_FORMAT() function formats a date as specified.
- SQL – MySQL DATE_SUB() FunctionThe MySQL DATE_SUB() function subtracts a time/date interval from a date and then returns the date.
- SQL – MySQL DAY() FunctionThe MySQL DAY() function returns the day of the month for a given date (a number from 1 to 31).
- SQL – MySQL DAYNAME() FunctionThe MySQL DAYNAME() function returns the weekday name for a given date.
- SQL – MySQL DAYOFMONTH() FunctionThe MySQL DAYOFMONTH() function returns the day of the month for a given date (a number from 1 to 31).
- SQL – MySQL DAYOFWEEK() FunctionThe MySQL DAYOFWEEK() function returns the weekday index for a given date (a number from 1 – Sunday to 7 – Saturday).
- SQL – MySQL DAYOFYEAR() FunctionThe MySQL DAYOFYEAR() function returns the day of the year for a given date (a number from 1 to 366).
- SQL – MySQL EXTRACT() FunctionThe MySQL EXTRACT() function extracts a part from a given date.
- SQL – MySQL FROM_DAYS() FunctionThe MySQL FROM_DAYS() function returns a date from a numeric datevalue.
- SQL – MySQL HOUR() FunctionThe MySQL HOUR() function returns the hour part for a given date (from 0 to 838).
- SQL – MySQL LAST_DAY() FunctionThe MySQL LAST_DAY() function extracts the last day of the month for a given date.
- SQL – MySQL LOCALTIME() FunctionThe MySQL LOCALTIME() function returns the current date and time as “YYYY-MM-DD HH-MM-SS” (string) or as YYYYMMDDHHMMSS.uuuuuu (numeric).
- SQL – MySQL LOCALTIMESTAMP() FunctionThe MySQL LOCALTIMESTAMP() function returns the current date and time as “YYYY-MM-DD HH-MM-SS” (string) or as YYYYMMDDHHMMSS.uuuuuu (numeric).
- SQL – MySQL MAKEDATE() FunctionThe MySQL MAKEDATE() function creates and returns a date based on a year and a number of days value.
- SQL – MySQL MAKETIME() FunctionThe MySQL MAKETIME() function creates and returns a time based on an hour, minute, and second value.
- SQL – MySQL MICROSECOND() FunctionThe MySQL MICROSECOND() function returns the microsecond part of a time/datetime (from 0 to 999999).
- SQL – MySQL MINUTE() FunctionThe MySQL MINUTE() function returns the minute part of a time/datetime (from 0 to 59).
- SQL – MySQL MONTH() FunctionThe MySQL MONTH() function returns the month part for a given date (a number from 1 to 12).
- SQL – MySQL MONTHNAME() FunctionThe MySQL MONTHNAME() function returns the name of the month for a given date.
- SQL – MySQL NOW() FunctionThe MySQL NOW() function returns the current date and time as “YYYY-MM-DD HH:MM:SS” (string) or as YYYYMMDDHHMMSS.uuuuuu (numeric).
- SQL – MySQL PERIOD_ADD() FunctionThe MySQL PERIOD_ADD() function adds a specified number of months to a period and will return the result formatted as YYYYMM.
- SQL – MySQL PERIOD_DIFF() FunctionThe MySQL PERIOD_DIFF() function returns the difference between two periods (both periods should be in the same format). The result will be in months.
- SQL – MySQL QUARTER() FunctionThe MySQL QUARTER() function returns the quarter of the year for a given date value (a number from 1 to 4).
- SQL – MySQL SECOND() FunctionThe MySQL SECOND() function returns the seconds part of a time/datetime (from 0 to 59).
- SQL – MySQL SEC_TO_TIME() FunctionThe MySQL SEC_TO_TIME() function returns a time value (in format HH:MM:SS) based on the specified seconds (positive or negative).
- SQL – MySQL STR_TO_DATE() FunctionThe MySQL STR_TO_DATE() function returns a date based on a string and a format.
- SQL – MySQL SUBDATE() FunctionThe MySQL SUBDATE() function subtracts a time/date interval from a date and then returns the new date.
- SQL – MySQL SUBTIME() FunctionThe MySQL SUBTIME() function subtracts time from a time/datetime expression and then returns the new time/datetime.
- SQL – MySQL SYSDATE() FunctionThe MySQL SYSDATE() function returns the current date and time as “YYYY-MM-DD HH:MM:SS” (string) or as YYYYMMDDHHMMSS (numeric).
- SQL – MySQL TIME() FunctionThe MySQL TIME() function extracts the time part from a given time/datetime, and returns “00:00:00” if not a datetime/time, or NULL if expression is NULL.
- SQL – MySQL TIME_FORMAT() FunctionThe MySQL TIME_FORMAT() function formats a time by a specified format.
- SQL – MySQL TIME_TO_SEC() FunctionThe MySQL TIME_TO_SEC() function converts a time value into seconds.
- SQL – MySQL TIMEDIFF() FunctionThe MySQL TIMEDIFF() function returns the difference between two time/datetime expressions (written in the same format).
- SQL – MySQL TIMESTAMP() FunctionThe MySQL TIMESTAMP() function returns a datetime value based on a date or datetime value.
- SQL – MySQL TO_DAYS() FunctionThe MySQL TO_DAYS() function returns the number of days between a date and year 0 (date “0000-00-00”).
- SQL – MySQL WEEK() FunctionThe MySQL WEEK() function returns the week number for a given date (a number from 0 to 53).
- SQL – MySQL WEEKDAY() FunctionThe MySQL WEEKDAY() function returns the weekday number for a given date.
- SQL – MySQL WEEKOFYEAR() FunctionThe MySQL WEEKOFYEAR() function returns the week number for a given date (a number from 1 to 53).
- SQL – MySQL YEAR() FunctionThe MySQL YEAR() function returns the year part for a given date (a number from 1000 to 9999).
- SQL – MySQL YEARWEEK() FunctionThe MySQL YEARWEEK() function returns the year and week number (a number from 0 to 53) for a given date.
SQL Notes:
- Any work being done to modify the structure of a database or delete tables or the the database itself should only be done after making a recent backup
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.