How to get the current date in Teradata with examples
Contents
Current Date in Teradata
In Teradata, we can fetch the current date using either CURRENT_DATE or DATE in the Select statement. Both of the build functions returns Current/Today’s date. The format of the date is ‘YYYY-MM-DD’ as below.
1 |
SELECT CURRENT_DATE |
1 |
SELECT DATE |
Add days to Current date in Teradata
Teradata allows to add the days to current date using either addition(+) operator or Interval function.
Method 1 :
1 |
SELECT CURRENT_DATE + 1 |
Method 2 :
Lets add 15 days to current date using Interval function as below.
1 |
SELECT CURRENT_DATE + INTERVAL '15' DAY |
Subtract days from Current Date in Teradata
If we want to get the yesterday date from the current date, we need to subtract 1 day from it. On the other hand, we can use the Interval function to subtract the days from the current date.
Method 1 :
1 |
SELECT CURRENT_DATE -1 |
Method 2:
Lets subtract 10 days from current date using Interval function as below.
1 |
SELECT CURRENT_DATE - INTERVAL '10' DAY |
Example for Current date usage in Teradata
Assume that we have the table Customer_Txn that contains the transaction details of customer as below.
If you want to fetch the transaction details for the last 15 days from this table, you can use the Current date and Interval function in the select query to get the results.
1 2 3 4 5 6 |
SELECT * FROM Banking_DB.Customer_Txn WHERE Transaction_DT BETWEEN Current_Date - INTERVAL '15' DAY AND Current_Date; |
Output
Read more about Teradata DATE functions: