[英]Hive: how to delete "" and change it to date format
我的數據集的日期列(tweet_stamp)顯示為“2020-01-29 00-21-29”,它是字符串格式。
我希望結果為 2020-01-29。
如何刪除字符串中的“”並將其更改為日期格式?
我嘗試了如下代碼 select to_date(from_unixtime(unix_timestamp(tweet_timestamp,'"yyyy-MM-dd 00-00-00"'), 'yyyy-MM-dd')) 作為 tweet_date;
但是,結果顯示NULL。
您不需要 unix_timestamp+from_unix_time 轉換,因為字符串的日期部分已經是正確的格式。 只需刪除雙引號,獲取子字符串並可選擇轉換為日期:
select date(substr(regexp_replace('"2020-01-29 00-21-29"','"',''),1,10)) --returns 2020-01-29
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.