DATE Function Examples | Teradata Vantage - Examples - Advanced SQL Engine - Teradata Database

SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-30
dita:mapPath
tpt1555966086716.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata Vantage™

Example 1: Returning the Current Date Based on INTERVAL -'08:00' HOUR TO MINUTE

This example assumes that the default format for DATE values is 'yy/mm/dd'. Consider the following statements:

SET TIME ZONE INTERVAL '01:00' HOUR TO MINUTE;
SELECT DATE AT TIME ZONE INTERVAL -'08:00' HOUR TO MINUTE;
SELECT DATE AT INTERVAL -'08:00' HOUR TO MINUTE;
SELECT DATE AT TIME ZONE INTERVAL -'08' HOUR;
SELECT DATE AT INTERVAL -'08' HOUR;
SELECT DATE AT TIME ZONE '-08:00';
SELECT DATE AT '-08:00';
SELECT DATE AT TIME ZONE '-8';
SELECT DATE AT '-8';
SELECT DATE AT TIME ZONE -8;
SELECT DATE AT -8;
SELECT DATE AT -8.0;

The above SELECT statements return the current date based on the time zone displacement, INTERVAL -'08:00' HOUR TO MINUTE. If the current timestamp at UTC is TIMESTAMP '2008-06-01 06:30:00.000000+00:00', these SELECT statements would return '08/05/31' as the date.

If the SELECT statement was specified without an AT clause or with an AT LOCAL clause, and the DBS Control flag TimeDateWZControl is enabled, the statement would return 
'08/06/01' as the current date based on the current session time and time zone displacement, INTERVAL '01:00' HOUR TO MINUTE. For example:

   SELECT DATE;
   SELECT DATE AT LOCAL;

The date returned is not adjusted to account for the start or end of daylight saving time.

Example 2: Changing the Presentation by 'mm-dd-yy'

Use the FORMAT phrase to change the presentation:

   SELECT DATE (FORMAT 'mm-dd-yy');
       Date
   --------
   03-30-96

Example 3: Returning the Current Date Based on Time Zone String 'America Pacific'

The following queries return the current date at the time zone displacement based on the time zone string, 'America Pacific'. Vantage determines the time zone displacement based on the time zone string and the CURRENT_TIMESTAMP AT '00:00' (that is, at UTC). The date returned is automatically adjusted to account for the start and end of daylight saving time.

   SELECT DATE AT TIME ZONE 'America Pacific';
   SELECT DATE AT 'America Pacific';

Example 4: Changing the Presentation by 'mmmbdd,byyyy'

Another form gives:

   SELECT DATE (FORMAT 'mmmbdd,byyyy');
           Date
   ------------
   Mar 30, 1996