Convert varchar to date in SQL / Teradata

event 2019-11-18 visibility 17,061 comment 0 insights
more_vert
insights Stats
Raymond Raymond Code Snippets & Tips

Code snippets and tips for various programming languages/frameworks. All code examples are under MIT or Apache 2.0 license unless specified otherwise. 

This code snippet shows how to convert string to date.

In Teradata, CAST function can be used to cast string/varchar to date. Format string can be used. For example, B represents blank/space while YYYY represents years.

Code snippet

SELECT CAST('2017-10-15' AS DATE FORMAT 'YYYY-MM-DD');

SELECT CAST('2017 10 15' AS DATE FORMAT 'YYYYBMMBDD');

SELECT CAST('2017 Oct 15' AS DATE FORMAT 'YYYYBMMMBDD');

SELECT CAST('15, Oct, 2017' AS DATE FORMAT 'DD,BMMM,BYYYY');

-- default ansi format

SELECT CAST('2017-10-15' AS DATE);

-- use to_date function

SELECT to_date('2017-10-15', 'YYYY-MM-DD');
More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts