AWS Athena和date_format

emm*_*ppa 3 amazon-web-services presto amazon-athena

在使用Amazon Athena服务格式化时间戳时,我遇到了一些问题.

select date_format(current_timestamp, 'y')

返回'y'(字符串).

我发现在Amazon Athena中设置日期格式的唯一方法是低谷CONCAT+ YEAR+ MONTH+ DAY函数,如下所示:

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

Dav*_*itz 12

select  current_timestamp

       ,date_format     (current_timestamp, '%Y_%m_%d')
       ,format_datetime (current_timestamp, 'y_M_d')
;
Run Code Online (Sandbox Code Playgroud)
+---------------------+------------+-----------+
|        _col0        |   _col1    |   _col2   |
+---------------------+------------+-----------+
| 2017-05-19 14:46:12 | 2017_05_19 | 2017_5_19 |
+---------------------+------------+-----------+
Run Code Online (Sandbox Code Playgroud)

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