Teradata Get Current date and Time

By | 2nd October 2021

In Teradata, while writing queries, it is always a good practice to make sure the query is capable of creating Point In Time(PIT) dataset. This is to make sure that the usage of DATE in the code is not hard-coded to produce the same record set every time.

Analysts and Data scientists used to create queries to simulate record sets for the historic dates. This can be achieved by passing the past date to the queries. This is mainly to check the model or dataset that they are generating is accurate enough to serve the purpose. Now, if the user has used CURRENT_DATE in the code for date filtering or comparison, it is easy to change that to any historic date.

Get the current date using the DATE function

SELECT DATE as TODAY;

The above statement will give the value of today’s date. A screenshot of the output is given below

Get Today’s date using CURRENT_DATE function

Teradata has another function that gives today’s date. It is the CURRENT_DATE function. There is no difference in the result between the DATE and CURRENT_DATE functions. Both will give the same result.

SELECT CURRENT_DATE as TODAY;

The above statement will also give the value of today’s date.

Get Current TimeStamp in Teradata

SELECT CURRENT_TIMESTAMP(0) as NOW;

This will give the output in the ‘YYYY-MM-DD hh:mm:ss:milliseconds’ format. A screenshot of the sample output is given below.

Also check,

  1. Create a table in Teradata with examples
  2. Export Teradata table to file using BTEQ
  3. Create a table using Select in Teradata
  4. Get DDL using a table name in Teradata

Leave a Reply