Convert string to timestamp in Hive

三世轮回 提交于 2019-11-30 09:37:44

Not sure what you mean by "better way" but you can always write your own function to handle the date conversion.

Looks like your format has three millisecond digits. I'd guess that, according to the SimpleDateFormat, you would need to use the following:

from_unixtime(unix_timestamp('20130502081559999', 'yyyyMMddHHmmssSSS'))

Hope that helps.

Suppose you have input file like this

file:///data/csv/temptable/temp.csv

1   2015-01-01  
2   2015-10-10 12:00:00.232
3   2016-02-02
4   2015-09-12 23:08:07.124

Then you can also try this approach:

create external table temptable(id string, datetime string) row format delimited fields terminated by '\t' stored as textfile LOCATION 'file:///data/csv/temptable';

create table mytime as select id, from_utc_timestamp(date_format(datetime,'yyyy-MM-dd HH:mm:ss.SSS'),'UTC') as datetime from temptable;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!