Teradata: how to convert varchar value (format ‘dd.mm.yyyy’) to date (format ‘yyyy-mm-dd’ )?

You need to apply a format during the cast, either Teradata style:

WHERE CAST(str AS DATE FORMAT 'dd.mm.yyyy') 
BETWEEN DATE '2015-06-01' AND DATE '2017-12-31'

or Oracle style:

WHERE TO_DATE(str, 'dd.mm.yyyy') 
BETWEEN DATE '2015-06-01' AND DATE '2017-12-31'

Btw, I added DATE in front of the string, it’s the recommended (and always reliable) way to write a date literal.

Leave a Comment