【问题标题】:AWS Athena and date_formatAWS Athena 和 date_format
【发布时间】:2017-10-19 06:45:15
【问题描述】:

我在使用 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))

【问题讨论】:

  • 不清楚您需要的结果是什么。请添加数据样本。

标签: amazon-web-services presto amazon-athena


【解决方案1】:
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 的第二个函数使其工作,删除 %s,而不是第一个。
猜你喜欢
  • 2020-05-22
  • 2018-01-28
  • 1970-01-01
  • 1970-01-01
  • 2019-05-03
  • 2019-06-18
  • 2018-08-12
  • 2020-06-27
  • 2018-11-06
相关资源
最近更新 更多