Example: Calculating the Difference in Days Between DATE Values - Advanced SQL Engine - Teradata Database

SQL Date and Time Functions and Expressions

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
xmd1556127764262.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1211
lifecycle
previous
Product Category
Teradata Vantageā„¢

The following query calculates the difference in days between the two DATE values.

SELECT (DATE '2007-05-10' - DATE '2007-04-28') DAY;

The result is the following:

(2007-05-10 - 2007-04-28) DAY
-----------------------------
12

The following query calculates the difference in months between the two DATE values.

SELECT (DATE '2007-05-10' - DATE '2007-04-28') MONTH;

The result is the following:

(2007-05-10 - 2007-04-28) MONTH
-------------------------------
1

There is a difference of 12 days between the two dates, which does not constitute one month. However, Teradata Database ignores the day values during the calculation and only considers the month values, so the result is an interval of one month indicating the difference between April and May.