小編給大家分享一下hive時間日期函數怎么用,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
1、hive取得當前日期時間:
1.1) 取得當前日期:
select current_date();
1.2) 取得當前日期時間:
select current_timestamp();
1.3) hive取得當前時間戳:
select unix_timestamp();
1.4) 時間戳轉日期:
select from_unixtime(1517725479,'yyyy-MM-dd HH:dd:ss');
1.5) 日期轉unix時間戳:
select to_nuix_timestamp('2017-01-01 12:12:12','yyyy-MM-dd HH:dd:ss');
1.6) hive取得當前時間:
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:dd:ss');
2、hive自動計算其他日期(昨天,今天):
hive中日期加減函數:date_add(start_date,num_days)
2.1) 取得昨天日期:
select date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-1);
select date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),1);
2.2) 取得明天日期:
select date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),1);
select date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-1);
3、hive取得兩個日期之間差值(差值為天數):
datediff(date1,date2):date1大于date2,返回值為正,否則,返回值為負。
select datediff(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-10));
select datediff(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),10));
4、字符串轉時間(字符串必須為:yyyy-MM-dd格式)
select to_date('2017-01-01 12:12:12');
5、日期、時間戳、字符串類型格式化輸出標準時間格式:
select date_format(current_timestamp(),'yyyy-MM-dd HH:mm:ss');
select date_format(current_date(),'yyyyMMdd');
select date_format('2017-01-01','yyyy-MM-dd HH:mm:ss'); --字符串必須滿足yyyy-MM-dd格式
6、utc時間轉換:
select from_utc_timestamp(current_timestamp(),8);
select to_utc_timestamp(current_timestamp(),8);
看完了這篇文章,相信你對“hive時間日期函數怎么用”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。