Argument Types and Rules - Analytics Database - Teradata Vantage

SQL Date and Time Functions and Expressions

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2023-10-30
dita:mapPath
cpk1628111786971.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
pxz1544241488545
lifecycle
latest
Product Category
Teradata Vantageā„¢
Expressions passed to this function must have one of the following data types:
  • DATE
  • TIMESTAMP
  • TIMESTAMP WITH TIME ZONE

The two argument to MONTHS_BETWEEN can be one of the preceding data types, but the two arguments must be the same data type. For example, you cannot pass a DATE as the first parameter and a TIMESTAMP as the second parameter.

Since TIMESTAMP values are stored in UTC time within the database and lack a time zone, the session time zone is used to interpret the time stamp value within the function. For TIMESTAMP WITH TIME ZONE values, the time zone component is used to interpret the time stamp value within the function.

If date_timestamp_value2 is:
  • Later than date_timestamp_value1, the result is negative.
  • Earlier than date_timestamp_value1, the result is positive.

If date_timestamp_value1 and date_timestamp_value2 are either the same days of the month or both last days of months, the result is always an integer. Otherwise, MONTHS_BETWEEN calculates the fractional portion of the result based on a 31-day month and considers the difference in time components of date_timestamp_value1 and date_timestamp_value2. The Gregorian calendar is supported.

Timestamps without a time zone are compared in the local time zone. This matters solely for the purpose of determining if two timestamps reside on the same day or are both the last day of a month. Timestamps with a time zone are converted to UTC before being compared in order to ensure the times are in the same zone.