TIMESTAMP

Start of changeThe TIMESTAMP function returns a TIMESTAMP WITHOUT TIME ZONE value from its argument or arguments.End of change

Start of changeSee TIMESTAMP_TZ for a similar function.End of change
Read syntax diagram
>>-TIMESTAMP(expression-1-+---------------+-)------------------><
                          '-,expression-2-'     

The schema is SYSIBM.

The rules for the arguments depend on whether the second argument is specified.

  • If only one argument is specified:
    Start of changeThe argument must be an expression that returns a value of one of the following built-in data types: a date, a timestamp, a character string, or a graphic string.End of change If expression-1 is a character or graphic string, it must not be a CLOB or DBCLOB and it must have one of the following values:
    • Start of changeA valid string representation of a date or timestamp with an actual length that is not greater than 255 bytes. A time zone in a string representation of a timestamp is ignored.End of change For the valid formats of string representations of timestamps, see String representations of datetime values.
    • A character string or graphic string with an actual length of 8 that is assumed to be a IBM® Z Store Clock value.
    • A character string with an actual length of 13 that is assumed to be a result from the GENERATE_UNIQUE function.
    • A character string or graphic string with an actual length of 14 that represents a valid date and time in the form yyyyxxddhhmmss, where yyyy is the year, xx is the month, dd is the day, hh is the hour, mm is the minute, and ss is the seconds.1
  • Start of changeIf both arguments are specified:,
    • If the data type of the second argument is not an integer:

      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. The second argument must be an expression that returns a value of one of the following built-in data types: a time, a character string, or a graphic string. A character string or graphic string must be a valid string representation of a time.

      If expression-1 is a character string or graphic string, it must not be a CLOB or DBCLOB, and its value must be a valid string representation of a date with an actual length that is not greater than 255 bytes. If expression-2 is a character string or graphic string, it must not be a CLOB or DBCLOB, and its value must be a valid string representation of a time with an actual length that is not greater than 255 bytes. For the valid formats of string representations of dates and times, see String representations of datetime values.

    • If the data type of the second argument is integer:

      The first argument must be an expression that returns a value of one of the following built-in data types: a timestamp, a date, a character string, or a graphic string. The second argument must be an integer constant in the range 0 to 12 that represents the timestamp precision.

      If expression-1 is a character string or graphic string, it must not be a CLOB or DBCLOB, and its value must be a valid string representation of a timestamp or a date with an actual length that is not greater than 255 bytes.

    End of change
Start of change

The result of the function is a TIMESTAMP WITHOUT TIME ZONE value.

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

If both arguments are specified and the second argument is not an integer:
The result is a TIMESTAMP(6) WITHOUT TIME ZONE value with the date that is specified by the first argument and the time that is specified by the second argument. The fractional seconds part of the timestamp is zero.
If both arguments are specified and the second argument is an integer:
The result is a TIMESTAMP WITHOUT TIME ZONE value with the precision that is specified in the second argument.
If only one argument is specified and it is a TIMESTAMP (p) WITHOUT TIME ZONE:
The result is that TIMESTAMP (p) WITHOUT TIME ZONE value.
If only one argument is specified and it is a TIMESTAMP(p) WITH TIME ZONE:
Start of changeThe result is the argument value, cast to TIMESTAMP(p) WITHOUT TIME ZONE. The value is the local timestamp, not UTC.End of change
If only one argument is specified and it is a date:
The result is that date with an assumed time of midnight that is cast to TIMESTAMP(0) WITHOUT TIME ZONE.
If only one argument is specified and it is a character or graphic string:
The result is the TIMESTAMP(6) WITHOUT TIME ZONE value that is represented by that string extended with any missing time information. If the argument is a string of length 14, the TIMESTAMP has a fractional seconds part of zero. The string value must not contain a specification of time zone.

If the arguments include only date information, the time information in the result value is all zeros.

The result can be null; if any argument is null, the result is the null value.

End of change

If an argument is a string with a CCSID that is not the same as the corresponding default CCSID at the server, the string is first converted to that CCSID.

The result CCSID is the appropriate CCSID of the argument encoding scheme and the result subtype is the appropriate subtype of the CCSID. If both arguments are specified and their encoding schemes are different, the result CCSID is the appropriate CCSID of the application encoding scheme.

Notes

Start of changeSyntax alternatives:End of change
Start of changeIf only one argument is specified, the CAST specification should be used for maximal portability. For more information, see CAST specification.End of change

Examples

Example: TIMESTAMP with a DATE column and a TIME column as arguments
Assume that table TABLEX contains a DATE column named DATECOL and a TIME column named TIMECOL. For some row in the table, assume that DATECOL represents 25 December 2008 and TIMECOL represents 17 hours, 12 minutes, and 30 seconds after midnight. The following function returns the value '2008-12-25-17.12.30.000000'.
   TIMESTAMP(DATECOL, TIMECOL)
Example: TIMESTAMP with a timestamp with time zone argument
Assume that host variable PRSTSZ contains '2008-02-29.20.00.000000 -08.30. The following statement returns the value '2008-02-29.20.00.000000':
SELECT TIMESTAMP(:PRSTSZ) 
	FROM PROJECT;
Example: TIMESTAMP with a timestamp and an integer as arguments
The following invocation of the TIMESTAMP function converts a timestamp string with 7 digits of fractional seconds to a TIMESTAMP(9) WITHOUT TIME ZONE value and returns a value of '2007-09-24-15.53.37.216247400':
	TIMESTAMP('2007-09-24-15.53.37.2162474',9);
1 Start of changeA character or graphic string with an actual length of 14 that represents a valid date and time (as allowed for the TIMESTAMP function) is also allowed as input to other scalar functions that accept a timestamp as an input argument.End of change