AWS Athena and date_format

emmekappa picture emmekappa · May 19, 2017 · Viewed 30.2k times · Source

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))

Answer

David דודו Markovitz picture David דודו Markovitz · May 19, 2017
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