17.00 - 17.05 - Scalar Arithmetic on Months Issues - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Date and Time Functions and Expressions

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
17.05
Release Date
June 2020
Content Type
Programming Reference
Publication ID
B035-1211-170K
Language
English (United States)

Consistent handling of a target month having fewer days than the month in the source date is an important issue for scalar arithmetic on month intervals because the concept of a month has no fixed definition.

All scalar function operations on dates use the Gregorian calendar. Peculiarities of the Gregorian calendar ensure that arithmetic operations such as adding 90 days (to represent three months) or 730 days (to represent two years) to a DATE value generally do not provide the desired result. For more information, see Gregorian Calendar Rules.

The ADD_MONTHS function uses an algorithm that lets you add or subtract a number of months to a date_expression or timestamp_expression and to obtain consistently valid results.

When deciding whether to use the Teradata SQL ADD_MONTHS function or ANSI SQL:2011 DateTime interval arithmetic, you are occasionally faced with choosing between returning a result that is valid, but probably neither desired nor expected, or not returning any result and receiving an error message.

A third option that does not rely on system-defined functions is to use the Teradata Database-defined Calendar view for date arithmetic.