Examples: NEXT_DAY - 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™

Example: Querying for the First Tuesday after a Specified Date

The following query:

SELECT NEXT_DAY(DATE '2009-12-20', 'TUESDAY'); 

returns the result 2009/12/22 since 12/22 is the next Tuesday after Sunday, Dec 20, 2009.

Example: Querying for the First Friday after a Specified Date

The following query:

SELECT NEXT_DAY(DATE '2009-12-20', 'FRIDAY');

returns the result 2009/12/25 since 12/25 is the next Friday after Sunday, Dec 20, 2009.

Example: Querying for the First Friday after a Different Specified Date

The following query:

SELECT NEXT_DAY(DATE '2009-12-25', 'FRIDAY'); 

returns the result 2010/01/01 since Jan 1, 2010 is the next Friday after Friday, Dec 25, 2009.

Example: Non-English day_values

NEXT_DAY (date_timestamp_value, day_value) works with the Specification for Data Formatting. This is an example of the Japanese tdlocaledef.txt and how NEXT_DAY works with those definitions.

// DBS System Formatting Data
// Day and month names
ShortDays {
"\u65e5";
"\u6708";
"\u706b";
"\u6c34";
"\u6728";
"\u91d1";
"\u571f"
}
LongDays {
"\u65e5\u66dc\u65e5";
"\u6708\u66dc\u65e5";
"\u706b\u66dc\u65e5";    /*火曜日*/
"\u6c34\u66dc\u65e5";
"\u6728\u66dc\u65e5";
"\u91d1\u66dc\u65e5";
"\u571f\u66dc\u65e5"
}
ShortMonths {
"1\u6708";
"2\u6708";
"3\u6708";
"4\u6708";
"5\u6708";
"6\u6708";
"7\u6708";
"8\u6708";
"9\u6708";
"10\u6708";
"11\u6708";
"12\u6708"
}

The following SQL fails with an error:

select next_day(to_date('2015/06/22','YYYY/MM/DD'),'Tue')  AS "日付";

Instead, use the Japanese day_value defined in the tdlocaledef.txt as follows:

select next_day(to_date('2015/06/22','YYYY/MM/DD'),'火曜日')  AS "日付" ;

Result:

日付
---------
2015/06/23
"\u706b\u66dc\u65e5"; indicates "Tuesday" in Japanese as shown.
Sel _UNICODE U&'#706b#66dc#65e5' UESCAPE '#';

Result:

' 火曜日'
-----------------
 火曜日