This topic describes the date and time functions supported by PolarDB-X.
Supported functions
PolarDB-X supports the following date and time functions.
Function | Description | Example |
---|
Function | Description | Example |
---|---|---|
ADDDATE(d,n) | Returns the date value of the day that is n days after the date d. | SELECT ADDDATE("2017-06-15", INTERVAL 10 DAY); The following result is returned:
|
ADDTIME(t,n) | Adds the time expression n to the t argument. |
|
CURDATE() | Returns the current date. | SELECT CURDATE(); The following result is returned:
|
CURRENT_DATE() | Returns the current date. |
The following result is returned:
|
CURRENT_TIME() | Returns the current time. |
The following result is returned:
|
CURRENT_TIMESTAMP() | Returns the current date and time. |
The following result is returned:
|
CURTIME() | Returns the current time. |
The following result is returned:
|
DATE() | Extracts a date value from a date or a datetime expression. |
The following result is returned:
|
DATEDIFF(d1,d2) | Calculates the number of days between the date d1 and the date d2. |
The following result is returned:
|
DATE_ADD(d,INTERVAL expr type) | Adds an interval to the date d. Valid values of the type argument are:
|
|
DATE_FORMAT(d,f) | Returns the date d in the format that is specified by the f argument. |
The following result is returned:
|
DATE_SUB(date,INTERVAL expr type) | Subtracts an interval from the specified date. | Execute the following statement to subtract two days from each value in the OrderDate
field of the Orders table.
|
DAY(d) | Returns the day component of the date d. | SELECT DAY("2017-06-15"); The following result is returned:
|
DAYNAME(d) | Returns what day the date d is in a week, such as Monday and Tuesday. |
The following result is returned:
|
DAYOFMONTH(d)) | Returns what day the date d is in a month. |
The following result is returned:
|
DAYOFWEEK(d) | Returns the weekday index for the date d. For example, the value 1 is returned for Sunday, and the value 2 is returned for Monday. |
The following result is returned:
|
DAYOFYEAR(d) | Returns what day the date d is in a year. |
The following result is returned:
|
EXTRACT(type FROM d) | Extracts the component specified by the type argument from the date d.
Valid values of the type argument are:
|
The following result is returned:
|
FROM_DAYS(n) | Returns the date value of the day that is n days after 0000-01-01. |
The following result is returned:
|
HOUR(t) | Returns the hour component of the t argument. |
The following result is returned:
|
LAST_DAY(d) | Returns the date value of the last day in the month of the specified date. |
The following result is returned:
|
LOCALTIME() | Returns the current date and time. |
The following result is returned:
|
LOCALTIMESTAMP() | Returns the current date and time. |
The following result is returned:
|
MAKEDATE(year, day-of-year) | Returns a date based on the year argument and the day-of-year argument. The day-of-year argument specifies the number of days that have elapsed from the start of the year that is specified by the year argument. |
The following result is returned:
|
MAKETIME(hour, minute, second) | Returns a time value based on the hour, minute, and second arguments. |
The following result is returned:
|
MICROSECOND(date) | Returns the microsecond component of the date argument. |
The following result is returned:
|
MINUTE(t) | Returns the minute component of the t argument. |
The following result is returned:
|
MONTHNAME(d) | Returns the name of the month of the specified date, such as November. |
The following result is returned:
|
MONTH(d) | Returns the number for the month in the specified date. The value ranges from 1 to 12. |
The following result is returned:
|
NOW() | Returns the current date and time. |
The following result is returned:
|
PERIOD_ADD(period, number) | Adds the number argument to the period argument. The number argument specifies the number of months you want to add. The period argument consists of a year component and a month component. |
The following result is returned:
|
PERIOD_DIFF(period1, period2) | Returns the number of months between the period1 argument and the period2 argument. |
The following result is returned:
|
QUARTER(d) | Returns the quarter of the date specified by the d argument. Possible return values: 1,2,3, and 4. |
The following result is returned:
|
SECOND(t) | Returns the second component of the t argument. |
The following result is returned:
|
SEC_TO_TIME(s) | Converts the s argument to a TIME value in the hh:mm:ss format. The s argument indicates the number of seconds that have elapsed since 00:00:00. |
The following result is returned:
|
STR_TO_DATE(string, format_mask) | Converts a string to a date. |
The following result is returned:
|
SUBDATE(d,n) | Subtracts n days from the date d. |
The following result is returned:
|
SUBTIME(t,n) | Subtracts n seconds from the t argument. |
The following result is returned:
|
SYSDATE() | Returns the current date and time. |
The following result is returned:
|
TIME(expression) | Extracts the time from the expression argument. |
The following result is returned:
|
TIME_FORMAT(t,f) | Returns the time specified by the t argument in the format specified by the f argument. |
The following result is returned:
|
TIME_TO_SEC(t) | Converts the t argument to the number of seconds that have elapsed since 00:00:00 until the time t. |
The following result is returned:
|
TIMEDIFF(time1, time2) | Returns the difference between the time1 argument and the time2 argument. |
The following result is returned:
|
TIMESTAMP(expression, interval) | Returns a datetime value. If you specify one argument, the function returns the datetime value of the specified argument. If you specify two arguments, the function adds the second argument to the first argument and returns the result as a datetime value. |
The following result is returned:
|
TO_DAYS(d) | Returns the number of days that have elapsed since January 1, 0000 until the date d. |
The following result is returned:
|
WEEK(d) | Returns the calendar week of the date d. Return values are integers from 0 to 53. |
The following result is returned:
|
WEEKDAY(d) | Returns the weekday index for the date d. For example, the value 0 is returned for Monday, and the value 1 is returned for Tuesday. |
The following result is returned:
|
WEEKOFYEAR(d) | Returns the calendar week of the date d. Return values are integers from 0 to 53. |
The following result is returned:
|
YEAR(d) | Returns the year component of the date d. |
The following result is returned:
|
YEARWEEK(date, mode) | Returns the year component of the specified date and the calendar week of the specified date. The calendar week is an integer from 0 to 53. For the mode argument, the value specifies the day of the week. For example, the value 0 represents Sunday and the value 1 represents Monday, and so on. |
The following result is returned:
|