15.00 - TO_TIMESTAMP - 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)

TO_TIMESTAMP

Purpose  

Converts string_expr or integer_expr to a TIMESTAMP data type.

Syntax  

where:

 

Syntax element …

Specifies …

TD_SYSFNLIB

the name of the database where the function is located.

string_expr

a character argument.

If the conversion fails, TO_TIMESTAMP returns an error.

format_arg

a character argument.

format_arg specifies the format of string_expr.

For valid format_arg values, see “TO_DATE” on page 801.

Any fractional seconds that are specified beyond 6 digits are truncated.

If format_arg is omitted, TO_TIMESTAMP uses a default timestamp format of YYYY-MM-DD HH24:MI:SS.FF6.

If format_arg is NULL, TO_TIMESTAMP returns NULL.

If format_arg is not valid, an error is returned.

integer_expr

a number argument.

POSIX epoch conversion is implicit in the TO_TIMESTAMP function when integer_expr is passed to the function.

POSIX epoch is the number of seconds that have elapsed since midnight Coordinated Universal Time (UTC) of January 1, 1970.

ANSI Compliance

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

Invocation

TO_TIMESTAMP is an embedded services system function. For information on activating and invoking embedded services functions, see “Embedded Services System Functions” on page 24.

Argument Types and Rules

Expressions passed to this function must be of VARCHAR data type or the following Numeric data types:

  • BYTEINT
  • SMALLINT
  • INTEGER
  • BIGINT
  • You can also pass arguments with data types that can be converted to the above types using the implicit data type conversion rules that apply to UDFs.

    Note: The UDF implicit type conversion rules are more restrictive than the implicit type conversion rules normally used by Teradata Database. If an argument cannot be converted to the required data type following the UDF implicit conversion rules, it must be explicitly cast.

    For details, see “Compatible Types” in SQL External Routine Programming.

    Result Type

    TO_TIMESTAMP is an overloaded scalar function whose return value data type is TIMESTAMP(6).

    Example  

    The following query:

    SELECT TO_TIMESTAMP ('January 15, 1989, 11:00 A.M.', 'Month dd, YYYY, HH: MI A.M.'); 

    returns the result 1989-01-15 11:00:00.000000.

    Example  

    The following query, an example of POSIX epoch conversion:

    SELECT TO_TIMESTAMP(242525);

    returns the result 1970-01-03 19:22:05.000000