Data types in Teradata
Timestamp and Date are different data types in Teradata. Each of them used for specific purpose in a Table.
- Timestamp – Date + Time details are stored in a single field
- Date – only Date value( YYYY/MM/DD) entered in a field.
Lets look at the Timestamp to Date conversion with an example.
Data type conversion in Teradata
CAST() function is used to perform the run time conversion between the compatible data types. We can use this function to convert the Timestamp to Date value.
CAST(<Timestamp value/column name> AS DATE)
Example : Timestamp to Date conversion in Teradata
Here is the customer_transaction table which contains the timestamp value for cre_ts column.
CAST(cre_ts as DATE) as cre_date -- Timestamp to Date conversion
As we mentioned the CAST(cre_ts as DATE) in the select query, the cre_ts column is converted from Timestamp to Date value as below.