简体   繁体   English

如何将 Julian 日期转换为 Hive 上的日历日期?

[英]How to convert Julian date to calendar date on Hive?

Is there any Hive function available to convert from Julian date to calendar date?是否有任何Hive function 可用于从Julian日期转换为calendar日期?

There are multiple types of Julian date. Julian日期有多种类型。 The Julian date I have takes 15001 for 2015-01-01 .我的Julian日期150012015-01-01

I couldn't find any relevant information on this page:我在此页面上找不到任何相关信息:

Hive Manual - Date Functions Hive 手册 - 日期函数

 date_add('2015-01-01', juliadate - 15001)

Just wanted to add.只是想补充。

The below is for julian date format yyyyDDD以下是朱利安日期格式yyyyDDD

Input_julian_date : 2006121 Input_julian_date : 2006121

substr(from_unixtime(unix_timestamp(cast(cast(Input_julian_date as int) as string),'yyyyDDD')),1,10) 

Output : 2006-05-01输出: 2006-05-01

Using "yyyyDDD" correctly converts Julian dates in Hive.使用“yyyyDDD”可以正确转换 Hive 中的 Julian 日期。

For example, I had a string column like "201707299999ABC" where the first 7 digits were the Julian date:例如,我有一个像“201707299999ABC”这样的字符串列,其中前 7 位数字是儒略日期:

TO_DATE(FROM_UNIXTIME(UNIX_TIMESTAMP(SUBSTRING(my_julian_column, 0, 7), "yyyyDDD")))

Produces 2017-03-13 as expected.按预期生产 2017-03-13。

Julian Date Format -- yyyyDDD The Date Format which is expected -- 'yyyy-MM-dd' Julian 日期格式 -- yyyyDDD 预期的日期格式 -- 'yyyy-MM-dd'

from_unixtime(unix_timestamp(cast(**julianl_date_col** as string),'yyyyDDD'),'yyyy-MM-dd') 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM