如何转换日期2017-sep-12到2017-09-12 HIVE中 [英] how to convert date 2017-sep-12 To 2017-09-12 in HIVE

查看:265
本文介绍了如何转换日期2017-sep-12到2017-09-12 HIVE中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在转换蜂巢中的日期时遇到了一个问题。我需要将2017-sep-12转换为2017-09-12。如何在HIVE中实现此功能

解决方案

使用 unix_timestamp(string date,string pattern)将给定的日期格式转换为从1970-01-01开始的秒数。然后使用 from_unixtime()转换为给定格式:

  hive>选择from_unixtime(unix_timestamp('2017-sep-12','yyyy-MMM-dd'),'dd-MM-yyyy'); 
OK
12-09-2017


I am facing one issue in converting the date in hive. I need to convert 2017-sep-12 To 2017-09-12 . How can i achieve this in HIVE

解决方案

Use unix_timestamp(string date, string pattern) to convert given date format to seconds passed from 1970-01-01. Then use from_unixtime() to convert to given format:

hive> select from_unixtime(unix_timestamp('2017-sep-12' ,'yyyy-MMM-dd'), 'dd-MM-yyyy');
OK
12-09-2017

这篇关于如何转换日期2017-sep-12到2017-09-12 HIVE中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆