TIMESTAMP Data Type

Teradata Vantage™ Data Types and Literals

brand
Software
Teradata Vantage
prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1143-162K

Purpose

Identifies a field as a TIMESTAMP value.

Syntax



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 zero through six inclusive.
The default precision is six.
attributes
Appropriate data type, column storage, or column constraint attributes.
See Core Data Type Attributes and Storage and Constraint Attributes for specific information.

ANSI Compliance

TIMESTAMP is non-ANSI standard. The Teradata Database stores a TIMESTAMP value in UTC.

Internal Representation of TIMESTAMP

Conceptually, TIMESTAMP is treated as a record composed of six fields, defined appropriately for the Gregorian calendar.

Field Name Minimum Value Maximum Value Storage Format
SECOND 00.000000 61.999999

This value accounts for leap seconds that can be added to the clock.

INTEGER (DECIMAL(8,6))
YEAR 0001 9999 SMALLINT
MONTH 01 12 BYTEINT
DAY 01 28, 29, 30, or 31

(depending on the month and year)

BYTEINT
HOUR 00 23 BYTEINT
MINUTE 00 59 BYTEINT

Although the record is composed of numeric fields, it is not treated as a numeric value.

The length of the internal stored form is 10 bytes.

External Representation of TIMESTAMP

TIMESTAMP types are imported and exported in record and indicator modes as CHARACTER data using the ANSI format string and the site-defined client character set.

WHEN fractional_seconds_precision is … THEN the type is … AND the format is …
0 CHAR(19) 'yyyy-mm-dd hh:mi:ss'
n

where n is 1 - 6

CHAR(20+n) 'yyyy-mm-dd hh:mi:ss.ss…'

The following table shows examples of how TIMESTAMP types are exported in record and indicator modes.

WHEN fractional_seconds_precision is … THEN length is … FOR example …
6 26 '1999-01-01 23:59:59.999999'
0 19 '1999-01-01 23:59:59'

TIMESTAMP Formats

For information about the TIMESTAMP formats and how to change them, see TIME and TIMESTAMP Formats.

Implicit and Explicit TIMESTAMP Conversion

Teradata Database performs implicit conversion from CHARACTER to TIMESTAMP types during assignment and comparison. This conversion is supported for CHAR and VARCHAR types only. You cannot convert a character data type of CLOB or CHAR/VARCHAR CHARACTER SET GRAPHIC to TIMESTAMP.

Teradata Database also performs implicit conversions from TIMESTAMP to DATE and TIME types. However, implicit TIMESTAMP to TIME conversion is not supported for comparisons.

You can use CAST to explicitly convert CHARACTER to TIMESTAMP types and from TIMESTAMP to DATE or TIME types.

For more information, see “Data Type Conversions” in Teradata Vantage™ SQL Functions, Expressions, and Predicates, B035-1145.

Example: TIMESTAMP Data Type

The following example shows TIMESTAMP used in a query.

SELECT item, quantity, saletime
FROM sales
WHERE saletime > TIMESTAMP '2000-08-25 10:14:59'
AND saletime < TIMESTAMP '2000-08-25 10:30:01';

Example: Difference Between Two TIMESTAMP Types

The difference between two TIMESTAMP types is an Interval type.

First define a table:

CREATE TABLE BillDateTime
(phone_no CHARACTER(10)
,start_time TIMESTAMP(0)
,end_time TIMESTAMP(0));

Now, determine the difference, specifying an Interval unit of DAY TO SECOND for the result:

SELECT (end_time - start_time) DAY(4) TO SECOND
FROM BillDateTime;

The DAY(4) specifies four digits of precision, and allows for a maximum of 9999 days, or approximately 27 years. The result looks like:

5 16:49:20.340000

Example: Comparison Between Two TIMESTAMP Values

The following example compares two TIMESTAMP numbers to find out if they are within 30 minutes of each other.

First define a table:

CREATE TABLE PhoneTime
(phone_no CHARACTER(10)
,start_time TIMESTAMP(0)
,end_time TIMESTAMP(0));

Note that the difference between two TIMESTAMP types is an Interval type:

SELECT phone_no
FROM PhoneTime
WHERE (end_time - start_time) DAY(4) TO MINUTE > INTERVAL '30' MINUTE;