How to convert date int to date datetype using SQL at Athena

Viewed 21

My columns has values like '20200908', '20211012', '20220203' and I'm trying to convert this values to date format, like '2020-09-08', in AWS Athena. How could I do this convert?

I have been trying in so many ways, but it didnt work

CONVERT( date, AP.VQL100_CC_date_opened, 23 )

select cast(cast(40835 as datetime) as date)

1 Answers

Use the DATE_PARSE() function:

SELECT DATE_PARSE('20200908', '%Y%m%d');

Note that dates don't really have any internal "format" in a SQL database, but rather are usually just stored as binary. If you really want to generate text then wrap the above with an extra call to DATE_FORMAT():

SELECT DATE_FORMAT(DATE_PARSE('20200908', '%Y%m%d'), '%Y-%m-%d');
Related