溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時(shí)間:2021-12-10 09:27:50 來源:億速云 閱讀:508 作者:小新 欄目:大數(shù)據(jù)

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

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

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

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

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

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

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

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

2、hive自動(dòng)計(jì)算其他日期(昨天,今天):

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取得兩個(gè)日期之間差值(差值為天數(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)時(shí)間(字符串必須為:yyyy-MM-dd格式)

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

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

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

select from_utc_timestamp(current_timestamp(),8);

select to_utc_timestamp(current_timestamp(),8);

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

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI