Teradata SQL - DATEADD Function Alternative for ADD / Subtract Days or Months

access_time 7 months ago visibility2756 comment 0

In ANSI SQL, you can use DATEADD function to easily add or subtract days/week/months/years from a date as the following code snippet shows:

SELECT DATEADD(month, 1, '20060830');
SELECT DATEADD(day, -1, '20060831');

However in Teradata this function is not implemented and you can use interval to add or subtract date units from date types.

Code snippets

Add days

select  EmployeeID,Birthday,
Birthday + Interval '2' day
from    TD_MS_SAMPLE_DB.Employee

Subtract days

select  EmployeeID,Birthday,
Birthday - Interval '2' day
from    TD_MS_SAMPLE_DB.Employee;

Add months

select  EmployeeID,Birthday,
Birthday + Interval '3' month
from    TD_MS_SAMPLE_DB.Employee

Subtract months

select  EmployeeID,Birthday,
Birthday - Interval '3' month
from    TD_MS_SAMPLE_DB.Employee
info Last modified by Administrator at 22 days ago copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Kontext Column

Created for everyone to publish data, programming and cloud related articles.
Follow three steps to create your columns.


Learn more arrow_forward

More from Kontext

local_offer teradata local_offer SQL local_offer teradata-functions

visibility 816
thumb_up 0
access_time 6 months ago

OREPLACE functions in Teradata can be used to replace or remove characters from a string. OREPACE is Teradata's extension to ASNI SQL. The usual REPLACE function is not available. REPLACE function is commonly implemented in many other SQL databases such as SQL Server, MySQL, BigQuery, Oracle, etc.

local_offer hive local_offer SQL local_offer hive-sql-ddl

visibility 59
thumb_up 0
access_time 2 months ago

This page shows how to create, drop, and truncate Hive tables via Hive SQL (HQL). Refer to  Differences between Hive External and Internal (Managed) Tables to understand the differences between managed and unmanaged tables in Hive.  Example: CREATE TABLE IF NOT EXISTS ...

About column

Code snippets for various programming languages/frameworks.

rss_feed Subscribe RSS