A common requirement when dealing with date/time in general revolves around the notion of SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z14, a topic that is worth exploring in the context of Elasticsearch and Elasticsearch SQL. Show
Elasticsearch has comprehensive support for both inside index names and queries. Inside Elasticsearch SQL the former is supported as is by passing the expression in the table name, while the latter is supported through the standard SQL SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z15. The table below shows the mapping between Elasticsearch and Elasticsearch SQL: Elasticsearch Elasticsearch SQL Index/Table datetime math SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z16 Query date/time math SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z17 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z18 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z19 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z20 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z21 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z22 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z23 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z24 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z25 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z26 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z27 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z28 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z29 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z30 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z15 allows either SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z32 and SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z33 to be mixed together or SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z34, SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z35, SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z36 and SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z37. Elasticsearch SQL accepts also the plural for each time unit (e.g. both SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z32 and SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z39 are valid). Example of the possible combinations below: Interval Description SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z40 1 year and 2 months SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z41 3 days and 4 hours SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z42 5 days, 6 hours and 12 minutes SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z43 3 days, 4 hours, 56 minutes and 1 second SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z44 2 days, 3 hours, 45 minutes, 1 second and 234567890 nanoseconds SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z45 123 hours and 45 minutes SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z46 65 hours, 43 minutes, 21 seconds and 12300000 nanoseconds SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z47 45 minutes, 1 second and 230000000 nanoseconds Date/time fields can be compared to expressions with the equality ( SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z48) and SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z49 operators: SELECT hire_date FROM emp WHERE hire_date = '1987-03-01||+4y/y'; hire_date ------------------------ 1991-01-26T00:00:00.000Z 1991-10-22T00:00:00.000Z 1991-09-01T00:00:00.000Z 1991-06-26T00:00:00.000Z 1991-08-30T00:00:00.000Z 1991-12-01T00:00:00.000Z SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z Basic arithmetic operators ( SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z50, SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z51, SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z52) support date/time parameters as indicated below: SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:00 SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-1 SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:00 SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-0 Functions that target date/time. Synopsis: CURRENT_DATE CURRENT_DATE() CURDATE() Input: none Output: date Description: Returns the date (no time part) when the current query reached the server. It can be used both as a keyword: SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z53 or as a function with no arguments: SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z54. Unlike CURRENT_DATE, SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z55 can only be used as a function with no arguments and not as a keyword. This method always returns the same value for its every occurrence within the same query. SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-12 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z0 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z1 Typically, this function (as well as its twin function is used for relative date filtering: SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z2 Synopsis: SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z3 Input: fractional digits; optional Output: time Description: Returns the time when the current query reached the server. As a function, SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z56 accepts precision as an optional parameter for rounding the second fractional digits (nanoseconds). The default precision is 3, meaning a milliseconds precision current time will be returned. This method always returns the same value for its every occurrence within the same query. SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z4 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z5 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z6 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z7 Typically, this function is used for relative date/time filtering: SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z8 Currently, using a precision greater than 6 doesn’t make any difference to the output of the function as the maximum number of second fractional digits returned is 6. Synopsis: SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z9 Input: fractional digits; optional Output: date/time Description: Returns the date/time when the current query reached the server. As a function, SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z57 accepts precision as an optional parameter for rounding the second fractional digits (nanoseconds). The default precision is 3, meaning a milliseconds precision current date/time will be returned. This method always returns the same value for its every occurrence within the same query. SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:000 SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:001 SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:002 Typically, this function (as well as its twin function is used for relative date/time filtering: SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:003 Currently, using a precision greater than 6 doesn’t make any difference to the output of the function as the maximum number of second fractional digits returned is 6. SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z58editSynopsis: SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:004 Input: string expression denoting the date/time unit to add to the date/datetime. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. integer expression denoting how many times the above unit should be added to/from the date/datetime, if a negative value is used it results to a subtraction from the date/datetime. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: datetime Description: Add the given number of date/time units to a date/datetime. If the number of units is negative then it’s subtracted from the date/datetime. If the second argument is a long there is possibility of truncation since an integer value will be extracted and used from that long. Datetime units to add/subtract unit abbreviations year years, yy, yyyy quarter quarters, qq, q month months, mm, m dayofyear dy, y day days, dd, d week weeks, wk, ww weekday weekdays, dw hour hours, hh minute minutes, mi, n second seconds, ss, s millisecond milliseconds, ms microsecond microseconds, mcs nanosecond nanoseconds, ns SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:005 SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:006 SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:007 SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:008 SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:009 SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z65editSynopsis: SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z0 Input: string expression denoting the date/time unit difference between the following two date/datetime expressions. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. start date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. end date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Subtract the second argument from the third argument and return their difference in multiples of the unit specified in the first argument. If the second argument (start) is greater than the third argument (end), then negative values are returned. Datetime difference units unit abbreviations year years, yy, yyyy quarter quarters, qq, q month months, mm, m dayofyear dy, y day days, dd, d week weeks, wk, ww weekday weekdays, dw hour hours, hh minute minutes, mi, n second seconds, ss, s millisecond milliseconds, ms microsecond microseconds, mcs nanosecond nanoseconds, ns SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z1 SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z2 SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z3 SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z4 For SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z72 and SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z73, SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z74 doesn’t do any rounding, but instead first truncates the more detailed time fields on the 2 dates to zero and then calculates the subtraction. SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z5 SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z6 SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z7 Synopsis: SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z8 Input: date/datetime/time expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. format pattern. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59 or an empty string, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: string Description: Returns the date/datetime/time as a string using the format specified in the 2nd argument. The formatting pattern is one of the specifiers used in the . If the 1st argument is of type SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z79, then pattern specified by the 2nd argument cannot contain date related units (e.g. dd, MM, yyyy, etc.). If it contains such units an error is returned. Ranges for month and day specifiers (%c, %D, %d, %e, %m) start at one, unlike MySQL, where they start at zero, due to the fact that MySQL permits the storing of incomplete dates such as 2014-00-00. Elasticsearch in this case returns an error. SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z9 SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-10 SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-11 Synopsis: SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-12 Input: date expression as a string. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59 or an empty string, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. parsing pattern. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59 or an empty string, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: date Description: Returns a date by parsing the 1st argument using the format specified in the 2nd argument. The parsing format pattern used is the one from SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z84. If the parsing pattern does not contain all valid date units (e.g. HH:mm:ss, dd-MM HH:mm:ss, etc.) an error is returned as the function needs to return a value of SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z85 type which will contain date part. SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-13 The resulting SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z85 will have the time zone specified by the user through the / REST/driver parameters with no conversion applied. SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-14 Synopsis: SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-15 Input: date/datetime/time expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. format pattern. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59 or an empty string, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: string Description: Returns the date/datetime/time as a string using the format specified in the 2nd argument. The formatting pattern used is the one from SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z84. If the 1st argument is of type SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z79, then pattern specified by the 2nd argument cannot contain date related units (e.g. dd, MM, yyyy, etc.). If it contains such units an error is returned. SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-16 SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-17 SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-18 Synopsis: SELECT - INTERVAL '49-1' YEAR TO MONTH result; result --------------- -49-19 Input: datetime expression as a string. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59 or an empty string, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. parsing pattern. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59 or an empty string, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: datetime Description: Returns a datetime by parsing the 1st argument using the format specified in the 2nd argument. The parsing format pattern used is the one from SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z84. If the parsing pattern contains only date or only time units (e.g. dd/MM/yyyy, HH:mm:ss, etc.) an error is returned as the function needs to return a value of SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0000 type which must contain both. SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:000 SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:001 If timezone is not specified in the datetime string expression and the parsing pattern, the resulting SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0000 will have the time zone specified by the user through the / REST/driver parameters with no conversion applied. SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:002 Synopsis: SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:003 Input: time expression as a string. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59 or an empty string, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. parsing pattern. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59 or an empty string, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: time Description: Returns a time by parsing the 1st argument using the format specified in the 2nd argument. The parsing format pattern used is the one from SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z84. If the parsing pattern contains only date units (e.g. dd/MM/yyyy) an error is returned as the function needs to return a value of SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z79 type which will contain only time. SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:004 SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:005 If timezone is not specified in the time string expression and the parsing pattern, the resulting SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z79 will have the offset of the time zone specified by the user through the / REST/driver parameters at the Unix epoch date ( SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0013) with no conversion applied. SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:006 Synopsis: SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:007 Input: string expression denoting the unit to extract from the date/datetime. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the specified unit from a date/datetime. It’s similar to but with different names and aliases for the units and provides more options (e.g.: SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0019). Datetime units to extract unit abbreviations year years, yy, yyyy quarter quarters, qq, q month months, mm, m dayofyear dy, y day days, dd, d week weeks, wk, ww weekday weekdays, dw hour hours, hh minute minutes, mi, n second seconds, ss, s millisecond milliseconds, ms microsecond microseconds, mcs nanosecond nanoseconds, ns tzoffset tz SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:008 SELECT INTERVAL '1' DAY - INTERVAL '2' HOURS AS result; result --------------- +0 22:00:009 SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z0 SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z1 For SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0020 and SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0021 the unit is extracted using the non-ISO calculation, which means that a given week is considered to start from Sunday, not Monday. SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z2 The SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0022 returns the total number of minutes (signed) that represent the time zone’s offset. SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z3 SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z4 Synopsis: SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z5 Input: string expression denoting the unit to which the date/datetime/interval should be truncated to. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. date/datetime/interval expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: datetime/interval Description: Truncate the date/datetime/interval to the specified unit by setting all fields that are less significant than the specified one to zero (or one, for day, day of week and month). If the first argument is SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0020 and the second argument is of SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z14 type, an error is thrown since the SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z14 data type doesn’t support a SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0020 time unit. Datetime truncation units unit abbreviations millennium millennia century centuries decade decades year years, yy, yyyy quarter quarters, qq, q month months, mm, m week weeks, wk, ww day days, dd, d hour hours, hh minute minutes, mi, n second seconds, ss, s millisecond milliseconds, ms microsecond microseconds, mcs nanosecond nanoseconds, ns SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z6 SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z7 SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z8 SELECT CAST('2018-05-13T12:34:56' AS DATETIME) - INTERVAL '2-8' YEAR TO MONTH AS result; result -------------------- 2015-09-13T12:34:56Z9 SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-00 SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-01 SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-02 SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-03 Synopsis: SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-04 Input: date/datetime/time expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. format pattern. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59 or an empty string, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: string Description: Returns the date/datetime/time as a string using the specified in the 2nd argument. The formatting pattern used is the one from Microsoft SQL Server Format Specification. If the 1st argument is of type SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z79, then pattern specified by the 2nd argument cannot contain date related units (e.g. dd, MM, yyyy, etc.). If it contains such units an error is returned. Format specifier SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0036 will be working similar to format specifier SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0037. It will return the fractional part of seconds, and the number of digits will be same as of the number of SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0038 provided as input (up to 9 digits). Result will contain SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0039 appended in the end to match with number of SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0036 provided. e.g.: for a time part SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0041 and pattern SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0042, the output string of the function would be: SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0043. Format specifier SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0044 will return year-of-era instead of one/two low-order digits. eg.: For year SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0045, SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0044 will be returning SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0045 instead of SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0048. For year SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0049, SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0044 format specifier will return SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0049. - Special characters like SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0052 , SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0053 and SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0054 will be returned as it is without any change. eg.: formatting date SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0055 with SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0056 will return SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0057 SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-05 SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-06 SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-07 Synopsis: SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-08 Input: date/datetime/time expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. format pattern. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59 or an empty string, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: string Description: Returns the date/datetime/time as a string using the format specified in the 2nd argument. The formatting pattern conforms to PostgreSQL Template Patterns for Date/Time Formatting. If the 1st argument is of type SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z79, then the pattern specified by the 2nd argument cannot contain date related units (e.g. dd, MM, YYYY, etc.). If it contains such units an error is returned. The result of the patterns SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0063 and SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0064 (time zone abbreviations) in some cases differ from the results returned by the SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0065 in PostgreSQL. The reason is that the time zone abbreviations specified by the JDK are different from the ones specified by PostgreSQL. This function might show an actual time zone abbreviation instead of the generic SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0066 or empty string or offset returned by the PostgreSQL implementation. The summer/daylight markers might also differ between the two implementations (e.g. will show SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0067 instead of SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0068 for Hawaii). The SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0069, SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0070, SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0071 pattern modifiers are not supported and will show up as SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0069, SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0070, SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0071 literals in the output. SELECT -2 * INTERVAL '3' YEARS AS result; result --------------- -6-09 CURRENT_DATE CURRENT_DATE() CURDATE()0 CURRENT_DATE CURRENT_DATE() CURDATE()1 Synopsis: CURRENT_DATE CURRENT_DATE() CURDATE()2 Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the day of the month from a date/datetime. CURRENT_DATE CURRENT_DATE() CURDATE()3 SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0077editSynopsis: CURRENT_DATE CURRENT_DATE() CURDATE()4 Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the day of the week from a date/datetime. Sunday is SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0080, Monday is SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0081, etc. CURRENT_DATE CURRENT_DATE() CURDATE()5 Synopsis: CURRENT_DATE CURRENT_DATE() CURDATE()6 Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the day of the year from a date/datetime. CURRENT_DATE CURRENT_DATE() CURDATE()7 Synopsis: Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: string Description: Extract the day of the week from a date/datetime in text format ( SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0086, SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0087…). CURRENT_DATE CURRENT_DATE() CURDATE()8 Synopsis: CURRENT_DATE CURRENT_DATE() CURDATE()9 Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the hour of the day from a date/datetime. SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-120 SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0090editSynopsis: SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-121 Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the day of the week from a date/datetime, following the ISO 8601 standard. Monday is SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0080, Tuesday is SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0081, etc. SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-122 SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:0095editSynopsis: SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-123 Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the week of the year from a date/datetime, following ISO 8601 standard. The first week of a year is the first week with a majority (4 or more) of its days in January. SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-124 Synopsis: SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-125 Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the minute of the day from a date/datetime. SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-126 SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z00editSynopsis: SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-127 Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the minute of the hour from a date/datetime. SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-128 Synopsis: Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the month of the year from a date/datetime. SELECT CURRENT_DATE AS result; result ------------------------ 2018-12-129 Synopsis: Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: string Description: Extract the month from a date/datetime in text format ( SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z07, SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z08…). SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z00 Synopsis: Input: none Output: datetime Description: This function offers the same functionality as function: returns the datetime when the current query reached the server. This method always returns the same value for its every occurrence within the same query. SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z01 Typically, this function (as well as its twin function is used for relative date/time filtering: SELECT INTERVAL 1 DAY + INTERVAL 53 MINUTES AS result; result --------------- +1 00:53:003 SELECT CAST('1969-05-13T12:34:56' AS DATETIME) + INTERVAL 49 YEARS AS result; result -------------------- 2018-05-13T12:34:56Z09editSynopsis: SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z03 Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the second of the minute from a date/datetime. SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z04 Synopsis: Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the year quarter the date/datetime falls in. SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z05 Synopsis: Input: none Output: date Description: This function offers the same functionality as function: returns the date when the current query reached the server. This method always returns the same value for its every occurrence within the same query. SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z06 Typically, this function (as well as its twin function is used for relative date filtering: SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z2 Synopsis: SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z08 Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the week of the year from a date/datetime. SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z09 Synopsis: Input: date/datetime expression. If SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59, the function returns SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z59. Output: integer Description: Extract the year from a date/datetime. SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z10 Synopsis: SELECT hire_date FROM emp WHERE hire_date IN ('1987-03-01||+2y/M', '1987-03-01||+3y/M'); hire_date ------------------------ 1989-03-31T00:00:00.000Z 1990-03-02T00:00:00.000Z11 Input: date/time function name date/datetime expression Output: integer Description: Extract fields from a date/datetime by specifying the name of a datetime function. The following Which Excel function returns the current system date and time?Insert a date or time whose value is updated. Is there a clock function in Excel?With this Excel time picker, you can easily manage appointments and timesheets or add a timestamp on a report. The Popup Clock add-in is a simple and straightforward time picker: Pops up next to a cell. Easy to use: select cells – set time, or date and time.
Which function returns the current date only?What is the NOW Function? The NOW Function[1] is categorized under Excel DATE/TIME functions. The function returns the current date and time.
Which function returns the current date but not the time?However, if you want to get just the current date – not the date and the time – you can use the CAST() function. This function takes any expression or any column name as the first argument.
|