[英]hive date cast issue
嗨,在我的Hive表中,我有一列包含這樣的日期值。
cl1
31102019000000
30112019000000
31122019000000
我試圖像這樣將列值轉換為日期格式
Select from_unixtime(unix_timestamp(cl1,'yyyy/MM/dd'),'yyyy-MM-dd') from table1;
它顯示NUll。 任何幫助將不勝感激。
您說您在dd-mm-yyyy中有日期,但隨后發布的數據中根本沒有任何連字符
假設31102019000000為2019年8月31日00:00:00
Select from_unixtime(unix_timestamp(cl1,'ddMMyyyyHHmmss'),'yyyy-MM-dd') from ...
將格式字符串與數據匹配。
試試這個
Select from_unixtime(unix_timestamp(REGEXP_REPLACE(cl1,'0+$',''),'ddMMyyyy'),'yyyy-MM-dd') from table1;
但這將在2020,2010年內失敗。 所以下面的查詢將是一個更好的選擇
Select from_unixtime(unix_timestamp(cast(cast(cl1/1000000 as bigint) as string),'ddMMyyyy'),'yyyy-MM-dd') from table1;
您試圖轉換為日期格式的UnixTimeStamp超出范圍。 您的時間戳記對應於:
GMT: Saturday, August 2, 2955 1:43:20 AM
Your time zone: Saturday, August 2, 2955 5:43:20 AM GMT+04:00
Relative: In 936 years
這是MYSql社區中的一個開放錯誤。 請檢查以下URL以供參考。 https://forums.mysql.com/read.php?20,385047,385132#msg-385132
MySQL數據庫的內置函數(如UNIX_TIMESTAMP())將在2038年1月19日世界標准時間03:14:07之后返回0。(來源: https : //en.wikipedia.org/wiki/Year_2038_problem )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.