emmekappa
emmekappa

Reputation: 812

AWS Athena and date_format

I have some issue while formatting a timestamp with Amazon Athena service.

select date_format(current_timestamp, 'y')

Returns just 'y' (the string).

The only way I found to format dates in Amazon Athena is trough CONCAT + YEAR + MONTH + DAY functions, like this:

select CONCAT(cast(year(current_timestamp) as varchar), '_', cast(day(current_timestamp) as varchar))

Upvotes: 19

Views: 92557

Answers (1)

David דודו Markovitz
David דודו Markovitz

Reputation: 44921

select  current_timestamp

       ,date_format     (current_timestamp, '%Y_%m_%d')
       ,format_datetime (current_timestamp, 'y_M_d')
;

+---------------------+------------+-----------+
|        _col0        |   _col1    |   _col2   |
+---------------------+------------+-----------+
| 2017-05-19 14:46:12 | 2017_05_19 | 2017_5_19 |
+---------------------+------------+-----------+

https://prestodb.io/docs/current/functions/datetime.html

Upvotes: 36

Related Questions