Teradata Calendar Functions

Teradata Calendar Functions

Teradata has introduced calendar functions in TD version 13.
These calendar functions provide better performance than using the Sys_Calendar.Calendar table for same purpose.
Calendar functions can be used on both Date and Timestamp columns.


Function

Description

td_day_of_week Returns week day in number ranging from 1-7 for the specified date
td_day_of_month Returns Day of the Month for the specified date
td_day_of_year Returns Day of the year for the specified date
td_day_of_calendar Returns number of days elapsed from January 01, 1900 for the specified date
td_weekday_of_month Returns nth Week of the month ranging from 1-4 for the specified date
td_week_of_month Returns nth Week of the month ranging from 0-4 for the specified date
td_week_of_year Returns Week of the year in number ranging from 0-52 for the specified date
td_week_of_calendar Returns Number of weeks elapsed from January 01, 1900 for the specified date
td_month_of_quarter Returns nth Month of the quarter ranging from 1 to 3 for the specified date
td_month_of_year Returns nth Month of the year ranging from 1 to 12 for the specified date
td_month_of_calendar Returns Number of months elapsed from January 01, 1900 for the specified date
td_quarter_of_year Returns Quarter of the year ranging from 1 to 4 for the specified date
td_quarter_of_calendar Returns Number of quarters elapsed from January 01, 1900 for the specified date
td_year_of_calendar Returns Year for the specified date


General Syntax:
any_calendar_function(date/timestamp column)

Assume the value CURRENT_DATE is 2018-10-17 for the below examples. And CURRENT_DATE can be replaced with any column of datatype DATE or TIMESTAMP.