2017-05-19 83 views
2

我在使用Amazon Athena服务格式化时间戳时遇到了一些问题。AWS Athena和date_format

select date_format(current_timestamp, 'y')

仅返回 'Y'(串)。

我发现格式的日期在亚马逊雅典娜的唯一途径是低谷CONCAT + YEAR + MONTH + DAY功能,像这样:

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

+0

它不是cle你需要的结果是什么?请添加数据示例。 –

回答

6
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