string 迄今为止的 HIVE 字符串铸造

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26992649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:18:53  来源:igfitidea点击:

HIVE STRING TO DATE CASTING

stringdatecastinghive

提问by new2world

I am facing problem in converting string to date type. While importing the data using hive I have got a column activation_date with type string (as I was unable to import it as date type) and I want to convert it into date type.

我在将字符串转换为日期类型时遇到问题。在使用 hive 导入数据时,我有一个类型为 string 的列 activation_date (因为我无法将其作为日期类型导入),我想将其转换为日期类型。

Example

例子

Activation_date 7-MAR-13 12-APR-12

Activation_date 7-MAR-13 12-APR-12

I want it as 07-03-2013 in hive.

我希望它在蜂巢中是 07-03-2013。

回答by Amar

A combination of date functions in hive can be used to get this.

可以使用 hive 中的日期函数组合来实现这一点。

select TO_DATE(from_unixtime(UNIX_TIMESTAMP('7-MAR-13', 'd-MMMM-yy'))) from table_name

从 table_name 中选择 TO_DATE(from_unixtime(UNIX_TIMESTAMP('7-MAR-13', 'd-MMMM-yy')))

Output:

输出:

2013-03-07

2013-03-07