Hi,
Interval is a data type in Teradata that represent displacement between two points in time.
ADD_MONTHS adds the months and years (Months * 12) to a specific date, while using Interval you can add YEAR, MONTH, DAY, HOUR, MINUTE AND EVEN Seconds to another interval.
Here in your case ADD_MONTHS intelligently identifies the Leap year and returns the correct date for example
SEL ADD_MONTHS(CAST('2013-08-29' AS DATE ),-6)
returns 2013-02-28
the returned date is 28 Feb as the year 2013 is not a leap year.
When you try to perform the same with
SEL CAST('2013-08-29' AS DATE ) -INTERVAL '6' MONTH
returns Invalid Date
It returns 2013-02-29, thats is actually invalid because 2013 is not a leap year.
So you can try Interval with any other date which do not return a leap FEB. for that you might have to perform some special calculation and ADD_MONTHS is better in that case.
Try SEL CAST('2013-07-29' AS DATE ) -INTERVAL '6' MONTH.
Hi,
Interval is a data type in Teradata that represent displacement between two points in time.
ADD_MONTHS adds the months and years (Months * 12) to a specific date, while using Interval you can add YEAR, MONTH, DAY, HOUR, MINUTE AND EVEN Seconds to another interval.
Here in your case ADD_MONTHS intelligently identifies the Leap year and returns the correct date for example
SEL ADD_MONTHS(CAST('2013-08-29' AS DATE ),-6)
returns 2013-02-28
the returned date is 28 Feb as the year 2013 is not a leap year.
When you try to perform the same with
SEL CAST('2013-08-29' AS DATE ) -INTERVAL '6' MONTH
returns Invalid Date
It returns 2013-02-29, thats is actually invalid because 2013 is not a leap year.
So you can try Interval with any other date which do not return a leap FEB. for that you might have to perform some special calculation and ADD_MONTHS is better in that case.
Try SEL CAST('2013-07-29' AS DATE ) -INTERVAL '6' MONTH.