How do I convert a date or timestamp to a string in Teradata

Database
Enthusiast

How do I convert a date or timestamp to a string in Teradata

In our database we have a system-generated ID that is built off of the timestamp. It’s not a date or time format, it’s a string, like (20130405103422), which is essentially the year, month, day, hour, minute and second that the record was created. I want to join it to another field, which is date, but I need to convert it first. How do I do that

2 REPLIES
Enthusiast

Re: How do I convert a date or timestamp to a string in Teradata

Try using the below query,

cast(cast('20130405233422' as timestamp(0) format 'YYYYMMDDHHMISS') as date format 'YYYY-MM-DD')

Enthusiast

Re: How do I convert a date or timestamp to a string in Teradata

please try this........

select cast(current_timestamp(0) as timestamp(0) format 'YYYYMMDDHHMISS')

;

 *** Query completed. One row found. One column returned.

 *** Total elapsed time was 1 second.

Current TimeStamp(0)

--------------------

      20140909090115