2017-05-19 84 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