15.00 - TIME-to-TIMESTAMP Conversion - Teradata Database

Teradata Database SQL Functions, Operators, Expressions, and Predicates

Product
Teradata Database
Release Number
15.00
Content Type
Programming Reference
Publication ID
B035-1145-015K
Language
English (United States)

TIME-to-TIMESTAMP Conversion

Purpose

Converts TIME or TIME WITH TIME ZONE to TIMESTAMP or TIMESTAMP WITH TIME ZONE using optional data attributes.

CAST Syntax

where:

 

Syntax element …

Specifies …

time_expression

the TIME expression to be converted.

fractional_seconds_precision

a single digit representing the number of significant digits in the fractional portion of the SECOND field.

Values for fractional_seconds_precision range from 0 through 6 inclusive.

The default precision is 6.

AT LOCAL

that the time zone displacement based on the current session time zone is used.

AT SOURCE [TIME ZONE]

that the time zone associated with time_expression is used in the following cases:

  • AT SOURCE TIME ZONE is specified.
  • AT SOURCE is specified without TIME ZONE and there is no column named source in the scope.
  • Otherwise, if AT SOURCE is specified without TIME ZONE and a column named source exists, then SOURCE references this column, and the value of the column is used as the time zone displacement for the CAST. If needed, the column value is implicitly converted to type INTERVAL HOUR(2) TO MINUTE. For details, see “AT LOCAL and AT TIME ZONE Time Zone Specifiers” on page 827. If there are multiple columns named source in the scope, an error is returned.

    AT [TIME ZONE] expression

    that the time zone displacement defined by expression is used. The data type of expression should be INTERVAL HOUR(2) TO MINUTE or it must be a data type that can be implicitly converted to INTERVAL HOUR(2) TO MINUTE. For details, see “AT LOCAL and AT TIME ZONE Time Zone Specifiers” on page 827.

    AT [TIME ZONE] time_zone_string

    that time_zone_string is used to determine the time zone displacement used for the CAST. For details, see “AT LOCAL and AT TIME ZONE Time Zone Specifiers” on page 827.

    data_attribute

    one of the following optional data attributes:

  • FORMAT
  • NAMED
  • TITLE
  • ANSI Compliance

    This is ANSI SQL:2011 compliant.

    As an extension to ANSI, CAST permits the use of the FORMAT phrase to enable alternative output formatting of DateTime data.

    The AT clause is ANSI SQL:2011 compliant.

    As an extension to ANSI, the AT clause is supported when using CAST to convert from TIME to TIMESTAMP. In addition, you can specify the time zone displacement using additional expressions besides an INTERVAL expression.

    Note: TIME (without time zone) and TIMESTAMP (without time zone) are not ANSI SQL:2011 compliant. Teradata Database internally converts a TIME or TIMESTAMP value to UTC based on the current session time zone or on a specified time zone.

    Teradata Conversion Syntax

    where:

     

    Syntax element …

    Specifies …

    time_expression

    the TIME expression to be converted.

    data_attribute

    one of the following optional data attributes:

  • FORMAT
  • NAMED
  • TITLE
  • fractional_seconds_precision

    a single digit representing the number of significant digits in the fractional portion of the SECOND field.

    Values for fractional_seconds_precision range from 0 through 6 inclusive.

    The default precision is 6.

    AT LOCAL

    that the time zone displacement based on the current session time zone is used.

    AT SOURCE [TIME ZONE]

    that the time zone associated with time_expression is used in the following cases:

  • AT SOURCE TIME ZONE is specified.
  • AT SOURCE is specified without TIME ZONE and there is no column named source in the scope.
  • Otherwise, if AT SOURCE is specified without TIME ZONE and a column named source exists, then SOURCE references this column, and the value of the column is used as the time zone displacement in the conversion. If needed, the column value is implicitly converted to type INTERVAL HOUR(2) TO MINUTE. For details, see “AT LOCAL and AT TIME ZONE Time Zone Specifiers” on page 827. If there are multiple columns named source in the scope, an error is returned.

    AT [TIME ZONE] expression

    that the time zone displacement defined by expression is used. The data type of expression should be INTERVAL HOUR(2) TO MINUTE or it must be a data type that can be implicitly converted to INTERVAL HOUR(2) TO MINUTE. For details, see “AT LOCAL and AT TIME ZONE Time Zone Specifiers” on page 827.

    AT [TIME ZONE] time_zone_string

    that time_zone_string is used to determine the time zone displacement used in the conversion. For details, see “AT LOCAL and AT TIME ZONE Time Zone Specifiers” on page 827.

    ANSI Compliance

    This is a Teradata extension to the ANSI SQL:2011 standard.

    The AT clause is ANSI SQL:2011 compliant.

    As an extension to ANSI, the AT clause is supported when using Teradata Conversion Syntax to convert from TIME to TIMESTAMP. In addition, you can specify the time zone displacement using additional expressions besides an INTERVAL expression.

    Note: TIME (without time zone) and TIMESTAMP (without time zone) are not ANSI SQL:2011 compliant. Teradata Database internally converts a TIME or TIMESTAMP value to UTC based on the current session time zone or on a specified time zone.

    Usage Notes

    If you specify the AT clause for a TIMESTAMP[(n)] without time zone target data type, the following table shows the result of the CAST function or Teradata conversion based on the various options specified. If the target precision is higher than the source precision, trailing zeros are added in the result to adjust the precision. If the target precision is lower than the source precision, an error is returned.

     

    IF you specify...

    AND the data type of time_expression is...

    THEN...

    AT LOCAL

    with or without TIME ZONE

    the source time_expression (in UTC) is adjusted by adding the time zone displacement based on the current session time zone. A local timestamp value is formed from CURRENT_DATE (at the above time zone displacement) and the time portion of time_expression obtained after the previous adjustment. The result is this local timestamp value adjusted to UTC by subtracting the above time zone displacement.

    This is the same as not specifying the AT clause.

    AT SOURCE

    (where SOURCE is a keyword and not a column reference)

    WITH TIME ZONE

    the source time_expression (in UTC) is adjusted by adding the time zone displacement of time_expression. A local timestamp value is formed from CURRENT_DATE (based on the time zone displacement of time_expression) and the time portion of time_expression obtained after the previous adjustment. The result is this local timestamp value adjusted to UTC by subtracting the time zone displacement of time_expression.

    AT SOURCE

    (where SOURCE is a keyword and not a column reference)

    without TIME ZONE

    an error is returned.

    AT SOURCE TIME ZONE

    WITH TIME ZONE

    the source time_expression (in UTC) is adjusted by adding the time zone displacement of time_expression. A local timestamp value is formed from CURRENT_DATE (based on the time zone displacement of time_expression) and the time portion of time_expression obtained after the previous adjustment. The result is this local timestamp value adjusted to UTC by subtracting the time zone displacement of time_expression.

    AT SOURCE TIME ZONE

    without TIME ZONE

    an error is returned.

    AT expression
    or
    AT TIME ZONE expression

    with or without TIME ZONE

    the source time_expression (in UTC) is adjusted by adding the time zone displacement defined by expression.

    A local timestamp value is formed from CURRENT_DATE at the above time zone displacement and the time portion of time_expression obtained after the above adjustment. The result is this local timestamp value adjusted to UTC by subtracting the above time zone displacement.

    AT time_zone_string
    or
    AT TIME ZONE time_zone_string

    with or without TIME ZONE

    the source time_expression (in UTC) is adjusted by adding the time zone displacement based on time_zone_string. The time zone displacement is determined based on time_zone_string, CURRENT_TIMESTAMP AT '00:00', and the TIME value of time_expression at UTC.

    A local timestamp value is formed from CURRENT_DATE at the above time zone displacement and the time portion of time_expression obtained after the above adjustment. The result is this local timestamp value adjusted to UTC by subtracting the above time zone displacement.

    If you specify the AT clause for a TIMESTAMP[(n)] WITH TIME ZONE target data type, the following table shows the result of the CAST function or Teradata conversion based on the various options specified. If the target precision is higher than the source precision, trailing zeros are added in the result to adjust the precision. If the target precision is lower than the source precision, an error is returned.

     

    IF you specify...

    AND the data type of time_expression is...

    THEN...

    AT LOCAL

    with or without TIME ZONE

    the source time_expression (in UTC) is adjusted by adding the time zone displacement based on the current session time zone. A local timestamp value is formed from CURRENT_DATE (at the above time zone displacement) and the time portion of time_expression obtained after the above adjustment. This resulting timestamp is adjusted to UTC, and the result value of the CAST at UTC is adjusted to the above time zone displacement.

    If the data type of time_expression is without time zone, this is the same as not specifying the AT clause.

    AT SOURCE

    (where SOURCE is a keyword and not a column reference)

    WITH TIME ZONE

    the source time_expression (in UTC) is adjusted by adding the time zone displacement of time_expression. A local timestamp value is formed from CURRENT_DATE (based on the time zone displacement of time_expression) and the time portion of time_expression obtained after the previous adjustment. This resulting timestamp is adjusted to UTC, and the result value of the CAST at UTC is adjusted to the time zone displacement of time_expression.

    AT SOURCE

    (where SOURCE is a keyword and not a column reference)

    without TIME ZONE

    an error is returned.

    AT SOURCE TIME ZONE

    WITH TIME ZONE

    the source time_expression (in UTC) is adjusted by adding the time zone displacement of time_expression. A local timestamp value is formed from CURRENT_DATE (based on the time zone displacement of time_expression) and the time portion of time_expression obtained after the previous adjustment. This resulting timestamp is adjusted to UTC, and the result value of the CAST at UTC is adjusted to the time zone displacement of time_expression.

    AT SOURCE TIME ZONE

    without TIME ZONE

    an error is returned.

    AT expression
    or
    AT TIME ZONE expression

    with or without TIME ZONE

    the source time_expression (in UTC) is adjusted by adding the time zone displacement defined by expression.

    A local timestamp value is formed from CURRENT_DATE (at the above time zone displacement) and the time portion of time_expression obtained after the above adjustment. This resulting timestamp is adjusted to UTC, and the result value of the CAST at UTC is adjusted to the above time zone displacement.

    AT time_zone_string
    or
    AT TIME ZONE time_zone_string

    with or without TIME ZONE

    the source time_expression (in UTC) is adjusted by adding the time zone displacement based on time_zone_string. The time zone displacement is determined based on time_zone_string, CURRENT_TIMESTAMP AT '00:00', and the TIME value of time_expression at UTC.

    A local timestamp value is formed from CURRENT_DATE (at the above time zone displacement) and the time portion of time_expression obtained after the above adjustment. This resulting timestamp is adjusted to UTC, and the result value of the CAST at UTC is adjusted to the above time zone displacement.

    Implicit TIME-to-TIMESTAMP Conversion

    Teradata Database performs implicit conversion from TIME to TIMESTAMP data types in some cases. However, implicit conversion from TIME to TIMESTAMP is not supported for comparisons. See “Implicit Conversion of DateTime types” on page 586.

    The following conversions are supported:

     

    From source type...

    To target type...

    TIME

    TIMESTAMP

    TIMESTAMP WITH TIME ZONE

    TIME WITH TIME ZONE

     

    TIMESTAMP

    TIMESTAMP WITH TIME ZONE

    Example  

    Assuming the current date is DATE '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, the following SELECT statements return the result: TIMESTAMP '2008-05-14 08:30:00'.

       SET TIME ZONE INTERVAL '09:00' HOUR TO MINUTE;
     
       SELECT CAST(TIME '08:30:00' AS TIMESTAMP(0));
       SELECT CAST(TIME '08:30:00' AS TIMESTAMP(0) AT LOCAL);

    The current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, is used to determine the UTC value '23:30:00' of the literal.

    For the CAST, the source expression value '23:30:00' at UTC is adjusted to the current session time zone displacement, INTERVAL '09:00' TO MINUTE, to yield '08:30:00'. A timestamp is formed from the current date '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, and the time portion of the source expression value '08:30:00'. Then, this timestamp, '2008-05-14 08:30:00', at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, is adjusted to UTC so that the CAST result is '2008-05-13 23:30:00' at UTC.

    The result value of the CAST at UTC is adjusted to the current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, so the result of the SELECT statements is: TIMESTAMP '2008-05-14 08:30:00'.

    Example  

    Assuming the current date is DATE '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, the following SELECT statements return the result: TIMESTAMP '2008-05-14 13:30:00'.

       SET TIME ZONE INTERVAL '09:00' HOUR TO MINUTE;
     
       SELECT CAST(TIME '08:30:00+04:00' AS TIMESTAMP(0));
       SELECT CAST(TIME '08:30:00+04:00' AS TIMESTAMP(0) AT LOCAL);

    The time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, in the literal is used to determine the UTC value '04:30:00' and time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, of the literal. For the CAST, the source expression value '04:30:00' at UTC is adjusted to the current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE to yield '13:30:00'.

    A timestamp is formed from the current date '2008-05-14' at time zone displacement, INTERVAL HOUR '09:00' TO MINUTE, and the time portion of the source expression value '13:30:00'. Then this timestamp, '2008-05-14 13:30:00', at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, is adjusted to UTC so that the CAST result is '2008-05-14 04:30:00' at UTC.

    The result value of the CAST at UTC is adjusted to the current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, so the result of the SELECT statements is: TIMESTAMP '2008-05-14 13:30:00'.

    Example  

    An error is returned for the following SELECT statements because the source expression does not have a time zone.

       SELECT CAST(TIME '08:30:00' AS TIMESTAMP(0) AT SOURCE TIME ZONE);
       SELECT CAST(TIME '08:30:00' AS TIMESTAMP(0) AT SOURCE);
       SELECT CAST(TIME '08:30:00' AS TIMESTAMP(0) WITH TIME ZONE 
          AT SOURCE TIME ZONE);
       SELECT CAST(TIME '08:30:00' AS TIMESTAMP(0) WITH TIME ZONE 
          AT SOURCE);

    Example  

    Assume that the current date is DATE '2008-05-14' at time zone displacement, INTERVAL '9:00' HOUR TO MINUTE, but the current date is DATE '2008-05-13' at time zone displacement, INTERVAL '04:00' HOUR TO MINUTE. The following SELECT statement returns the result: TIMESTAMP '2008-05-13 13:30:00'.

       SET TIME ZONE INTERVAL '09:00' HOUR TO MINUTE;
       SELECT CAST(TIME '08:30:00+04:00' AS TIMESTAMP(0) 
          AT SOURCE TIME ZONE);

    The time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, in the literal is used to determine the UTC value '04:30:00' and time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, of the literal. For the CAST, the source expression value '04:30:00' at UTC is adjusted to the time zone displacement of the source, INTERVAL '04:00' HOUR TO MINUTE, to yield '08:30:00'.

    A timestamp is formed from the current date '2008-05-13' at time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, and the time portion of the source expression value '08:30:00' obtained after the above adjustment. Then this timestamp '2008-05-13 08:30:00' at time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, is adjusted to UTC so that the CAST result is '2008-05-13 04:30:00' at UTC.

    The result value of the CAST at UTC is adjusted to the current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, so the result of the SELECT statement is: TIMESTAMP '2008-05-13 13:30:00'.

    Example  

    Assume that the current date is DATE '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, but the current date is DATE '2008-05-13' at time zone, INTERVAL -'08:00' HOUR TO MINUTE. The following SELECT statement returns the result: TIMESTAMP '2008-05-14 08:30:00'.

       SET TIME ZONE INTERVAL '09:00' HOUR TO MINUTE;
       SELECT CAST(TIME '08:30:00' AS TIMESTAMP(0) AT -8);

    The current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, is used to determine the UTC value '23:30:00' of the literal. For the CAST, the source expression value '23:30:00' at UTC is adjusted to the target time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, to yield '15:30:00'.

    A timestamp is formed from the current date '2008-05-13' at time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, and the time portion of the source expression value '15:30:00' obtained after the above adjustment. Then this resulting timestamp '2008-05-13 15:30:00' at time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, is adjusted to UTC so that the CAST result is '2008-05-13 23:30:00' at UTC.

    The result value of the CAST at UTC is adjusted to the current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, so the result of the SELECT statement is: TIMESTAMP '2008-05-14 08:30:00'.

    Example  

    Assume that the current date is DATE '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, but the current date is DATE '2008-05-13' at time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE. The following SELECT statement returns the result: TIMESTAMP '2008-05-14 13:30:00'.

       SET TIME ZONE INTERVAL '09:00' HOUR TO MINUTE;
       SELECT CAST(TIME '08:30:00+04:00' AS TIMESTAMP(0) AT -8);

    The time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, in the literal is used to determine the UTC value '04:30:00' and time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, of the literal. For the CAST, the source expression value '04:30:00' at UTC is adjusted to the target time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, to yield '20:30:00'.

    A timestamp is formed from the current date '2008-05-13' at time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, and the time portion of the source expression value '20:30:00' obtained after the above adjustment. Then this timestamp '2008-05-13 20:30:00' at time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, is adjusted to UTC so that the CAST result is '2008-05-14 04:30:00' at UTC.

    The result value of the CAST at UTC is adjusted to the current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, so the result of the SELECT statement is: TIMESTAMP '2008-05-14 13:30:00'.

    Example  

    Assuming the current date is DATE '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, the following SELECT statements return the result: TIMESTAMP '2008-05-14 08:30:00+09:00'.

       SET TIME ZONE INTERVAL '09:00' HOUR TO MINUTE;
       SELECT CAST(TIME '08:30:00' AS TIMESTAMP(0) WITH TIME ZONE);
       SELECT CAST(TIME '08:30:00' AS TIMESTAMP(0) WITH TIME ZONE AT LOCAL);

    The current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, is used to determine the UTC value '23:30:00' of the literal. For the CAST, the source expression value '23:30:00' at UTC is adjusted to the current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, to yield '08:30:00'.

    A timestamp is formed from the current date '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, and the time portion of the source expression value '08:30:00' obtained after the above adjustment. Then this timestamp '2008-05-14 08:30:00' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, is adjusted to UTC so that the CAST result is '2008-05-13 23:30:00' at UTC with time zone displacement, INTERVAL '09:00' HOUR TO MINUTE.

    The result value of the CAST at UTC is adjusted to time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, so the result of the SELECT statements is: TIMESTAMP '2008-05-14 08:30:00+09:00'.

    Example  

    Assuming the current date is DATE '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, the following SELECT statement returns the result: TIMESTAMP '2008-05-14 13:30:00+09:00'.

       SET TIME ZONE INTERVAL '09:00' HOUR TO MINUTE;
       SELECT CAST(TIME '08:30:00+04:00' AS TIMESTAMP(0) 
          WITH TIME ZONE AT LOCAL);

    The time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, in the literal is used to determine the UTC value '04:30:00' and time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, of the literal. For the CAST, the source expression value '04:30:00 at UTC is adjusted to the current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, to yield '13:30:00'.

    A timestamp is formed from the current date '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, and the time portion of the source expression value '13:30:00' obtained after the above adjustment. Then this timestamp '2008-05-14 13:30:00' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, is adjusted to UTC so that the CAST result is '2008-05-14 04:30:00' at UTC with time zone displacement, INTERVAL '09:00' HOUR TO MINUTE.

    The result value of the CAST at UTC is adjusted to time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, so the result of the SELECT statement is: TIMESTAMP '2008-05-14 13:30:00+09:00'.

    Example  

    Assume that the current date is DATE '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, but the current date is DATE '2008-05-13' at time zone displacement, INTERVAL '04:00' HOUR TO MINUTE. The following SELECT statement returns the result: TIMESTAMP '2008-05-14 08:30:00+04:00'.

       SET TIME ZONE INTERVAL '09:00' HOUR TO MINUTE;
       SELECT CAST(TIME '08:30:00+04:00' AS TIMESTAMP(0) WITH TIME ZONE);

    The time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, in the literal is used to determine the UTC value '04:30:00' and time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, of the literal. For the CAST, the source expression value '04:30:00' at UTC is adjusted to the current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, to yield '13:30:00'.

    A timestamp is formed from the current date '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, and the time portion of the source expression value '13:30:00' obtained after the above adjustment. Then this timestamp '2008-05-14 13:30:00' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, is adjusted to UTC so that the CAST result is '2008-05-14 04:30:00' at UTC with time zone displacement, INTERVAL '04:00' HOUR TO MINUTE.

    The result value of the CAST at UTC is adjusted to time zone displacement, INTERVAL '04:00' INTERVAL TO MINUTE, so the result of the SELECT statement is: TIMESTAMP '2008-05-14 08:30:00+04:00'.

    Example  

    Assume that the current date is DATE '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, but the current date is DATE '2008-05-13' at time zone displacement, INTERVAL '04:00' HOUR TO MINUTE. The following SELECT statement returns the result: TIMESTAMP '2008-05-13 08:30:00+04:00'.

       SET TIME ZONE INTERVAL '09:00' HOUR TO MINUTE;
       SELECT CAST(TIME '08:30:00+04:00' AS TIMESTAMP(0) WITH TIME ZONE 
          AT SOURCE);

    The time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, in the literal is used to determine the UTC value '04:30:00' and time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, of the literal. For the CAST, the source expression value '04:30:00' at UTC is adjusted to the time zone displacement of the source expression, INTERVAL '04:00' HOUR TO MINUTE, to yield '08:30:00'.

    A timestamp is formed from the current date '2008-05-13' at time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, and the time portion of the source expression value '08:30:00' obtained after the above adjustment. Then this timestamp '2008-05-13 08:30:00' at time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, is adjusted to UTC so that the CAST result is '2008-05-13 04:30:00' at UTC with time zone displacement, INTERVAL '04:00' HOUR TO MINUTE.

    The result value of the CAST at UTC is adjusted to time zone, INTERVAL '04:00' HOUR TO MINUTE, so the result of the SELECT statement is: TIMESTAMP '2008-05-13 08:30:00+04:00'. The current session time zone has no effect.

    Example  

    Assume that the current date is DATE '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, but the current date is DATE '2008-05-13' at time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE. The following SELECT statement returns the result: TIMESTAMP '2008-05-13 15:30:00-08:00'.

       SET TIME ZONE INTERVAL '09:00' HOUR TO MINUTE;
       SELECT CAST(TIME '08:30:00' AS TIMESTAMP(0) WITH TIME ZONE AT -8);

    The current session time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, is used to determine the UTC value '23:30:00' of the literal. For the CAST, the source expression value '23:30:00' at UTC is adjusted to the target time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, to yield '15:30:00'.

    A timestamp is formed from the current date '2008-05-13' at time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, and the time portion of the source expression value '15:30:00' obtained after the above adjustment. Then this timestamp '2008-05-13 15:30:00' at time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, is adjusted to UTC so that the CAST result is '2008-05-13 23:30:00' at UTC with time zone displacement, INTERVAL ‑'08:00' HOUR TO MINUTE.

    The result value of the CAST at UTC is adjusted to time zone displacement, INTERVAL ‑'08:00' HOUR TO MINUTE, so the result of the SELECT statement is: TIMESTAMP '2008-05-13 15:30:00-08:00'.

    Example  

    Assume that the current date is DATE '2008-05-14' at time zone displacement, INTERVAL '09:00' HOUR TO MINUTE, but the current date is DATE '2008-05-13' at time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE. The following SELECT statement returns the result: TIMESTAMP '2008-05-13 20:30:00-08:00'.

       SET TIME ZONE INTERVAL '09:00' HOUR TO MINUTE;
       SELECT CAST(TIME '08:30:00+04:00' AS TIMESTAMP(0) WITH TIME ZONE 
          AT -8);

    The time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, in the literal is used to determine the UTC value '04:30:00' and time zone displacement, INTERVAL '04:00' HOUR TO MINUTE, of the literal. For the CAST, the source expression value '04:30:00' at UTC is adjusted to the target time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, to yield '20:30:00'.

    A timestamp is formed from the current date '2008-05-13' at time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, and the time portion of the source expression value '20:30:00' obtained after the above adjustment. Then this timestamp '2008-05-13 20:30:00' at time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE, is adjusted to UTC so that the CAST result is '2008-05-14 04:30:00' at UTC with time zone displacement, INTERVAL ‑'08:00' HOUR TO MINUTE.

    The result value of the CAST at UTC is adjusted to time zone displacement, INTERVAL ‑'08:00' HOUR TO MINUTE, so the result of the SELECT statement is: TIMESTAMP '2008-05-13 20:30:00-08:00'. The current session time zone has no effect.

    Example  

    In this example, the current timestamp is:

                   Current TimeStamp(6)
       --------------------------------
       2010-03-09 19:23:27.620000+00:00

    The following statement converts the TIME value '08:30:00' to a TIMESTAMP value, where the time zone displacement is based on the time zone string, 'America Pacific'.

       SELECT CAST(TIME '08:30:00' AS TIMESTAMP(0) AT 'America Pacific');

    The result of the query is:

                  08:30:00
       -------------------
       2010-03-09 08:30:00

    Example  

    In this example, the current timestamp is:

                   Current TimeStamp(6)
       --------------------------------
       2010-03-09 19:23:27.620000+00:00

    The following statement converts the TIME value '08:30:00+04:00' to a TIMESTAMP value, where the time zone displacement is based on the time zone string, 'America Pacific'.

       SELECT CAST(TIME '08:30:00+04:00' AS TIMESTAMP(0)
          AT 'America Pacific');

    The result of the query is:

            08:30:00+04:00
       -------------------
       2010-03-10 04:30:00

    Related Topics

    For details on data types and data attributes, see SQL Data Types and Literals.