在" MMM-yyyy"中需要时间戳。蜂巢中的格式

时间:2017-07-29 08:33:48

标签: datetime hadoop hive hiveql bigdata

你能帮我把时间格式化为" MMM-yyyy"来自hive中current_date的格式?

提前多多感谢。

例如:

col1           col2
12-09-2016     SEP-2016
21-10-2017     OCT-2017

1 个答案:

答案 0 :(得分:1)

select from_unixtime(unix_timestamp(CURRENT_DATE, 'yyyy-MM-dd HH:mm:ss'),'MMM-yyyy') 
AS currentdate from db.table_name;

示例:

hive> select from_unixtime(unix_timestamp(CURRENT_DATE, 'yyyy-MM-dd HH:mm:ss'),'MMM-yyyy')
    > AS currentdate from default.test limit 1;
OK
Jul-2017
Time taken: 0.043 seconds, Fetched: 1 row(s)
hive>