hive時間日期函數(shù)怎么用

小編給大家分享一下hive時間日期函數(shù)怎么用,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

成都創(chuàng)新互聯(lián)主要從事網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)東源,10多年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):028-86922220

1、hive取得當(dāng)前日期時間:

1.1) 取得當(dāng)前日期:
select current_date();

1.2) 取得當(dāng)前日期時間:
select current_timestamp();

1.3) hive取得當(dāng)前時間戳:
select unix_timestamp();

1.4) 時間戳轉(zhuǎn)日期:
select from_unixtime(1517725479,'yyyy-MM-dd HH:dd:ss');

1.5) 日期轉(zhuǎn)unix時間戳:
select to_nuix_timestamp('2017-01-01 12:12:12','yyyy-MM-dd HH:dd:ss');

1.6) hive取得當(dāng)前時間:
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:dd:ss');

2、hive自動計算其他日期(昨天,今天):

hive中日期加減函數(shù):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取得兩個日期之間差值(差值為天數(shù)):

datediff(date1,date2):date1大于date2,返回值為正,否則,返回值為負(fù)。

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、字符串轉(zhuǎn)時間(字符串必須為:yyyy-MM-dd格式)

select to_date('2017-01-01 12:12:12');

5、日期、時間戳、字符串類型格式化輸出標(biāo)準(zhǔn)時間格式:

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時間轉(zhuǎn)換:

select from_utc_timestamp(current_timestamp(),8);

select to_utc_timestamp(current_timestamp(),8);

看完了這篇文章,相信你對“hive時間日期函數(shù)怎么用”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

文章名稱:hive時間日期函數(shù)怎么用
文章網(wǎng)址:http://bm7419.com/article46/ijphhg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、響應(yīng)式網(wǎng)站、網(wǎng)站改版、ChatGPT商城網(wǎng)站、Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)