17

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

David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88
emmekappa
  • 792
  • 1
  • 6
  • 9

2 Answers2

31
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

David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88
0

This will work as well with js, if it helps anyone...

const current = new Date();
date: `${current.getFullYear()}-${current.getMonth() + 1}-${current.getDate()}`
DoGzTheFiGhTeR
  • 296
  • 2
  • 9