Varchar to date

Database
The Teradata Database channel includes discussions around advanced Teradata features such as high-performance parallel database technology, the optimizer, mixed workload management solutions, and other related technologies.
Highlighted
Enthusiast

Varchar to date

Hi I have a column with varchar(50) that stores value like 2016-12-06 17:59:18.940

I need to cast to date and timestamp. How can i do it.

 


Accepted Solutions
Junior Contributor

Re: Varchar to date

Timestamp:
select cast('2016-12-06 17:59:18.940' as timestamp(3))

Date:
select cast(cast('2016-12-06 17:59:18.940' as timestamp(3)) as date)
select To_Date('2016-12-06 17:59:18.940', 'yyyy-mm-dd hh24:mi:ss.ff3')
1 ACCEPTED SOLUTION
1 REPLY
Junior Contributor

Re: Varchar to date

Timestamp:
select cast('2016-12-06 17:59:18.940' as timestamp(3))

Date:
select cast(cast('2016-12-06 17:59:18.940' as timestamp(3)) as date)
select To_Date('2016-12-06 17:59:18.940', 'yyyy-mm-dd hh24:mi:ss.ff3')