Date & Time
You can find definitions for Date and time functions from adddate to yearweek:
Function | Description |
---|---|
adddate | Adds “days” days to expr. |
addtime | Datetime number of days to be added to expr. |
conver_tz | CONVERT_TZ() converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value. |
curdate | Returns the current date as a value in “YYYY-MM-DD” or YYYYMMDD format, depending on whether the function is used in a string or numeric context. |
curtime | Returns the current time as a value in “HH:MM:SS” or HHMMSS format, depending on whether the function is used in a string or numeric context. |
current_time | CURRENT_TIME() is a synonym for CURTIME().' |
daterip | Extracts the date part of the date or datetime expression expr. |
date_adds | Adds an interval to a date. |
date_diff | DATEDIFF() returns expr1 ? expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation. |
date_format | Formats the date value according to the format string. |
date_subs | Substracts an interval from a date. |
day | DAY() is a synonym for DAYOFMONTH(). |
dayname | Returns the name of the weekday for date. |
dayofmonth | Returns the day of the month for date, in the range 0 to 31. |
dayofweek | Returns the weekday index for date (1 = Sunday, 2 = Monday, ?, 7 = Saturday). These index values correspond to the ODBC standard. |
dayofyear | Returns the day of the year for date, in the range 1 to 366. |
extract | Extracts parts from the date. |
from_days | Given a day number N, returns a DATE value. |
from_unixtime | Returns a representation of the unix_timestamp argument as a value in “YYYY-MM-DD HH:MM:SS” or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context. unix_timestamp is an internal timestamp value such as is produced by the UNIX_TIMESTAMP() function. |
hour | Returns the hour for time. The range of the return value is 0 to 23 for time-of-day values. However, the range of TIME values actually is much larger, so HOUR can return values greater than 23. |
last_days | Takes a date or datetime value and returns the corresponding value for the last day of the month. Returns NULL if the argument is invalid. |
localtime | LOCALTIME() is a synonym for NOW(). |
localtimestamp | LOCALTIMESTAMP() is a synonym for NOW(). |
makedate | Returns a date, given year and day-of-year values. dayofyear must be greater than 0 or the result is NULL. |
maketime | Returns a time value calculated from the hour, minute, and second arguments. |
microsecond | Returns the microseconds from the time or datetime expression expr as a number in the range from 0 to 999999 |
minute | Returns the minute for time, in the range 0 to 59. |
month | Returns the month for date, in the range 0 to 12. |
monthname | Returns the full name of the month for date. |
now | Returns the current date and time as a value in “YYYY-MM-DD HH:MM:SS” or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context. |
period_add | Adds N months to period P (in the format YYMM or YYYYMM). Returns a value in the format YYYYMM. Note that the period argument P is not a date value. |
period_diff | Returns the number of months between periods P1 and P2. P1 and P2 should be in the format YYMM or YYYYMM. Note that the period arguments P1 and P2 are not date values. |
quarter | Returns the number of months between periods P1 and P2. P1 and P2 should be in the format YYMM or YYYYMM. Note that the period arguments P1 and P2 are not date values. |
second | Returns the second for time, in the range 0 to 59. |
sec_to_time | Returns the seconds argument, converted to hours, minutes, and seconds, as a value in “HH:MM:SS” or HHMMSS format, depending on whether the function is used in a string or numeric context. |
str_to_date | This is the inverse of the DATE_FORMAT() function. It takes a string str and a format string format. STR_TO_DATE() returns a DATETIME value if the format string contains both date and time parts, or a DATE or TIME value if the string contains only date or time parts. |
subtime | SUBTIME() returns expr1 ? expr2 expressed as a value in the same format as expr1. expr1 is a time or datetime expression, and expr2 is a time expression. |
sysdate | Returns the current date and time as a value in “YYYY-MM-DD HH:MM:SS” or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context. |
time | Extracts the time part of the time or datetime expression expr and returns it as a string. |
timediff | IMEDIFF() returns expr1 ? expr2 expressed as a time value. expr1 and expr2 are time or date-and-time expressions, but both must be of the same type. |
timestamp | With a single argument, this function returns the date or datetime expression expr as a datetime value. With two arguments, it adds the time expression expr2 to the date or datetime expression expr1 and returns the result as a datetime value. |
timestampadd | Adds the integer expression interval to the date or datetime expression datetime_expr. The unit for interval is given by the unit argument, which should be one of the following values: FRAC_SECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR. |
timestamp | Returns the integer difference between the date or datetime expressions datetime_expr1 and datetime_expr2. The unit for the result is given by the unit argument. The legal values for unit are the same as those listed in the description of the TIMESTAMPADD() function. |
time_format | This is used like the DATE_FORMAT() function, but the format string may contain format specifiers only for hours, minutes, and seconds. Other specifiers produce a NULL value or 0. |
time_to_sec | Returns the time argument, converted to seconds. |
to_days | Given a date, returns a day number (the number of days since year 0). |
unix_timestamp | If called with no argument, returns a Unix timestamp (seconds since “1970-01-01 00:00:00” UTC) as an unsigned integer. If UNIX_TIMESTAMP() is called with a date argument, it returns the value of the argument as seconds since “1970-01-01 00:00:00” UTC. date may be a DATE string, a DATETIME string, a TIMESTAMP, or a number in the format YYMMDD or YYYYMMDD. The server interprets date as a value in the current time zone and converts it to an internal value in UTC. |
utc_date | Returns the current UTC date as a value in “YYYY-MM-DD” or YYYYMMDD format, depending on whether the function is used in a string or numeric context. |
utc_time | Returns the current UTC time as a value in “HH:MM:SS” or HHMMSS format, depending on whether the function is used in a string or numeric context. |
utc_timestamp | Returns the current UTC date and time as a value in “YYYY-MM-DD HH:MM:SS” or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context. |
week | This function returns the week number for date. The two-argument form of WEEK() allows you to specify whether the week starts on Sunday or Monday and whether the return value should be in the range from 0 to 53 or from 1 to 53. |
weekday | Returns the weekday index for date (0 = Monday, 1 = Tuesday, ? 6 = Sunday). |
weekofyear | Returns the calendar week of the date as a number in the range from 1 to 53. WEEKOFYEAR() is a compatibility function that is equivalent to WEEK(date,3). |
year | Returns the year for date, in the range 1000 to 9999, or 0 for the “zero” date. |
yearweek | Returns year and week for a date. The mode argument works exactly like the mode argument to WEEK(). The year in the result may be different from the year in the date argument for the first and the last week of the year. |
Parent Topic: Functions