TIMESTAMP

The TIMESTAMP function returns a timestamp from its argument or arguments.

Read syntax diagramSkip visual syntax diagram
>>-TIMESTAMP--(--expression-1--+-----------------+--)----------><
                               '-,--expression-2-'      

expression-1
If only one argument is specified, the argument must be an expression that returns a value of one of the following built-in data types: a timestamp, a character string, or a graphic string. If expression-1 is a character or graphic string, it must not be a CLOB or DBCLOB and its value must be one of the following:
  • A valid string representation of a timestamp. For the valid formats of string representations of timestamps, see String representations of datetime values.
  • A string with an actual length of 7 that represents 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.
  • A character string with an actual length of 13 that is assumed to be a result from a GENERATE_UNIQUE function. For information on GENERATE_UNIQUE, see GENERATE_UNIQUE.

If both arguments are specified, the first argument must be an expression that returns a value of one of the following built-in data types: a date, a character string, or a graphic string. If expression-1 is a character or graphic string, it must not be a CLOB or DBCLOB and its value must be a valid string representation of a date.

expression-2
An expression that returns a value of one of the following built-in data types: a time, a character string, or a graphic string.

If expression-2 is a character or graphic string, it must not be a CLOB or DBCLOB, and its value must be a valid string representation of a time. For the valid formats of string representations of times, see String representations of datetime values.

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

The other rules depend on whether the second argument is specified:

  • If both arguments are specified:

    The result is a timestamp with the date specified by the first argument and the time specified by the second argument. The microsecond part of the timestamp is zero.

  • If only one argument is specified and it is a timestamp:

    The result is that timestamp.

  • If only one argument is specified and it is a character string:

    The result is the timestamp represented by that character string. If the argument is a character string of length 14, the timestamp has a microsecond part of zero.

When a string representation of a date, time, or timestamp is SBCS data with a CCSID that is not the same as the default CCSID for SBCS data, that value is converted to adhere to the default CCSID for SBCS data before it is interpreted and converted to a timestamp value.

When a string representation of a date, time, or timestamp is mixed data with a CCSID that is not the same as the default CCSID for mixed data, that value is converted to adhere to the default CCSID for mixed data before it is interpreted and converted to a timestamp value.

Note

Syntax alternatives: The CAST specification should be used to increase the portability of applications when only one argument is specified. For more information, see CAST specification.

Example

  • Assume the following date and time values:
      SELECT TIMESTAMP( DATE('1988-12-25'), TIME('17.12.30') )
        FROM SYSIBM.SYSDUMMY1
    Returns the value '1988-12-25-17.12.30.000000'.