15.10 - INTERVAL DAY TO SECOND Literals - Teradata Database

Teradata Database SQL Data Types and Literals

prodname
Teradata Database
vrm_release
15.10
category
Programming Reference
featnum
B035-1143-151K

Declares an INTERVAL DAY TO SECOND value in an expression.

where:

 

Syntax element …

Specifies …

sign

an optional minus sign to indicate a negative interval. The default is a positive interval.

The sign must be outside the apostrophes that enclose string.

string

one to four digits representing the number of days, followed by a pad character and two digits representing the number of hours, followed by a colon and two digits representing the number of minutes. This is followed by a colon and two digits representing the number of seconds, and optionally followed by a decimal point and 1 to 6 digits representing fractional seconds. The decimal point is required if the fractional seconds are included. Besides the pad character, no other spaces or new line characters are allowed between the apostrophes.

Note: For the digits representing the number of days, only digits are parsed and converted to numeric. For example, '1.05' is treated as '105'.

INTERVAL DAY TO SECOND literals are partly ANSI SQL:2011 compliant.

In the ANSI definition, the optional sign is within the apostrophes; the Teradata implementation places the optional sign outside the apostrophes.

INTERVAL DAY TO SECOND

For details on the INTERVAL DAY TO SECOND type, see “INTERVAL DAY TO SECOND Data Type” on page 163.

This example adds an interval of 30 days, 12 hours, 30 minutes, and 30.5 seconds to the current system timestamp.

   SELECT INTERVAL '30 12:30:30.5' DAY TO SECOND + CURRENT_TIMESTAMP;
   

The result looks like this:

   ( 30 12:30:30.5+Current TimeStamp)
   ----------------------------------
     1999-12-04 03:19:27.780000+00:00

In the following query, the first decimal point is ignored and the result is an interval of 10 days, 10 hours, 30 minutes, and 30.5 seconds.

   SELECT INTERVAL '1.0 10:30:30.5' DAY TO SECOND;