0% found this document useful (0 votes)
39 views3 pages

Library: White Papers: Dates, Times and Timestamps in Teradata (Thru TD12)

The document discusses dates, times, and timestamps in Teradata, including: 1) How to define date, time, and timestamp columns with different number formats. While timestamps can be defined with up to 6 decimal places, MP-RAS on Intel only tracks up to 2 decimal places. 2) Different ways to specify date literals, including matching the column format, using an explicit format like 'DDMMMYYYY', or using the ANSI standard 'DATE' format. 3) How to calculate the number of days between two dates by subtracting one date column from another.

Uploaded by

marri.siva09
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views3 pages

Library: White Papers: Dates, Times and Timestamps in Teradata (Thru TD12)

The document discusses dates, times, and timestamps in Teradata, including: 1) How to define date, time, and timestamp columns with different number formats. While timestamps can be defined with up to 6 decimal places, MP-RAS on Intel only tracks up to 2 decimal places. 2) Different ways to specify date literals, including matching the column format, using an explicit format like 'DDMMMYYYY', or using the ANSI standard 'DATE' format. 3) How to calculate the number of days between two dates by subtracting one date column from another.

Uploaded by

marri.siva09
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Enter your sea

Web w

Recent Threads Library: White Papers


Attachments

Library

White Papers
Dates, Times and Timestamps in
Teradata
UDFs (thru TD12)
Written by Geoffrey Rommel
Teradata PDFs

IBM PDFs
Dates, times, and timestamps in Teradata can be a little tricky.
This document explains how to do various things that you may
Quick Reference want to do. It is current through TD 12.

Rules of Conduct

FAQs Preliminaries

Join the Forum The examples below use Teradata syntax, so they assume that
you are running in BTEQ. If you are using SQL Assistant
(Queryman), be sure to uncheck the option box "Allow use of
ODBC SQL Extensions in queries". Changing the Date Time
Archives Format in your ODBC data source to AAA or IIA may also help.

Sample Index datecol means a column defined as DATE.

2010 2004
2009 2003
2008 2002
Defining columns and formats
2007 2001
Times and timestamps can be defined with any number of
2006 2000 decimal places from 0 to 6 (time(0), timestamp(6), etc.). As it
2005 1999 turns out, however, MP-RAS on Intel doesn’t keep track of
anything beyond 2 decimal places (hundredths of seconds), so in
many cases it is useless to define columns with more than
2 decimal places. If, however, you are loading data from another
server, that data could have digits down to the microsecond.

The formats for all columns are described in the SQL Reference:
Data Types and Literals, Chapter 9. In V2R5 and later releases,
you can specify many different formats for time and timestamp
fields.

Dates

Literals

Date literals can be specified in many ways:

-- in the same format as the column they are being compared to

where infamy_date = '12/07/1941'

-- with an explicit format

where infamy_date = '07Dec1941' (date, format


'DDMMMYYYY')

-- in ANSI standard form (must be preceded by the keyword


DATE)

where infamy_date = date '1941-12-07'

-- in numeric form (not recommended)

where infamy_date = 411207

Observe in the examples above that the word DATE must be


used to specify the data type. To get the system date, therefore,
CURRENT_DATE is a better choice than DATE.

Number of days between two dates

datecol - datecol will return the number of days between


two dates.

select date '2003-08-15' - date '2003-01-01';

You might also like