DB2 10.5 for Linux, UNIX, and Windows

DATE scalar function

The DATE function returns a date from a value.

Read syntax diagramSkip visual syntax diagram
>>-DATE--(--expression--)--------------------------------------><

The schema is SYSIBM.

expression
An expression that returns a value of one of the following built-in data types: DATE, TIMESTAMP, numeric, or character string that is not a CLOB.

A value with a numeric data type must be a positive number with an integral value less than or equal to 3 652 059.

A character string must be a valid string representation of a date or timestamp or a string of length 7. If the value is a string of length 7, it must represent a valid date in the form yyyynnn , where yyyy are digits denoting a year, and nnn are digits between 001 and 366, denoting a day of that year.

In a Unicode database, if an expression returns a value of a graphic string data type, the value is first converted to a character string before the function is executed.

The result of the function is a DATE. If the argument can be null, the result can be null; if the argument is null, the result is the null value.

The other rules depend on the data type of the argument:
  • If the argument is a DATE, TIMESTAMP, or valid string representation of a date or timestamp:
    • The result is the date part of the value.
  • If the argument is a number:
    • The result is the date that is n-1 days after January 1, 0001, where n is the integral part of the number.
  • If the argument is a string with a length of 7:
    • The result is the date represented by the string.

Examples

Assume that the column RECEIVED (whose data type is TIMESTAMP) has an internal value equivalent to '1988-12-25-17.12.30.000000'.
  • Example 1: This example results in an internal representation of '1988-12-25'.
       DATE(RECEIVED)
  • Example 2: This example results in an internal representation of '1988-12-25'.
       DATE('1988-12-25')
  • Example 3: This example results in an internal representation of '1988-12-25'.
       DATE('25.12.1988')
  • Example 4: This example results in an internal representation of '0001-02-04'.
       DATE(35)