Hive日期函數(shù)語(yǔ)法介紹

這篇文章主要介紹“Hive日期函數(shù)語(yǔ)法介紹”,在日常操作中,相信很多人在Hive日期函數(shù)語(yǔ)法介紹問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Hive日期函數(shù)語(yǔ)法介紹”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

成都創(chuàng)新互聯(lián)公司自2013年創(chuàng)立以來(lái),先為芮城等服務(wù)建站,芮城等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為芮城企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。

日期函數(shù)UNIX時(shí)間戳轉(zhuǎn)日期函數(shù): from_unixtime語(yǔ)法:from_unixtime(bigint unixtime[, string format]) 
返回值: string
說(shuō)明: 轉(zhuǎn)化UNIX時(shí)間戳(從1970-01-01 00:00:00 UTC到指定時(shí)間的秒數(shù))到當(dāng)前時(shí)區(qū)的時(shí)間格式
舉例:
hive> select from_unixtime(1323308943,'yyyyMMdd') from dual;
20111208

獲取當(dāng)前UNIX時(shí)間戳函數(shù): unix_timestamp語(yǔ)法:   unix_timestamp() 
返回值:   bigint
說(shuō)明: 獲得當(dāng)前時(shí)區(qū)的UNIX時(shí)間戳
舉例:
hive>   select unix_timestamp() from dual;
1323309615

日期轉(zhuǎn)UNIX時(shí)間戳函數(shù): unix_timestamp語(yǔ)法:unix_timestamp(string date) 
返回值:   bigint
說(shuō)明: 轉(zhuǎn)換格式為“yyyy-MM-dd HH:mm:ss“的日期到UNIX時(shí)間戳。如果轉(zhuǎn)化失敗,則返回0。
舉例:
hive>   select unix_timestamp('2011-12-07 13:01:03') from dual;
1323234063

指定格式日期轉(zhuǎn)UNIX時(shí)間戳函數(shù): unix_timestamp語(yǔ)法:   unix_timestamp(string date, string pattern) 
返回值:   bigint
說(shuō)明: 轉(zhuǎn)換pattern格式的日期到UNIX時(shí)間戳。如果轉(zhuǎn)化失敗,則返回0。
舉例:
hive>   select unix_timestamp('20111207 13:01:03','yyyyMMdd HH:mm:ss') from dual;
1323234063

日期時(shí)間轉(zhuǎn)日期函數(shù): to_date語(yǔ)法:   to_date(string timestamp) 
返回值:   string
說(shuō)明: 返回日期時(shí)間字段中的日期部分。
舉例:
hive>   select to_date('2011-12-08 10:03:01') from dual;
2011-12-08

日期轉(zhuǎn)年函數(shù): year語(yǔ)法:   year(string date) 
返回值: int
說(shuō)明: 返回日期中的年。
舉例:
hive>   select year('2011-12-08 10:03:01') from dual;
2011
hive>   select year('2012-12-08') from dual;
2012

日期轉(zhuǎn)月函數(shù): month語(yǔ)法: month   (string date) 
返回值: int
說(shuō)明: 返回日期中的月份。
舉例:
hive>   select month('2011-12-08 10:03:01') from dual;
12
hive>   select month('2011-08-08') from dual;
8

日期轉(zhuǎn)天函數(shù): day語(yǔ)法: day   (string date) 
返回值: int
說(shuō)明: 返回日期中的天。
舉例:
hive>   select day('2011-12-08 10:03:01') from dual;
8
hive>   select day('2011-12-24') from dual;
24

日期轉(zhuǎn)小時(shí)函數(shù): hour語(yǔ)法: hour   (string date) 
返回值: int
說(shuō)明: 返回日期中的小時(shí)。
舉例:
hive>   select hour('2011-12-08 10:03:01') from dual;
10

日期轉(zhuǎn)分鐘函數(shù): minute語(yǔ)法: minute   (string date) 
返回值: int
說(shuō)明: 返回日期中的分鐘。
舉例:
hive>   select minute('2011-12-08 10:03:01') from dual;
3

日期轉(zhuǎn)秒函數(shù): second語(yǔ)法: second   (string date) 
返回值: int
說(shuō)明: 返回日期中的秒。
舉例:
hive>   select second('2011-12-08 10:03:01') from dual;
1

日期轉(zhuǎn)周函數(shù): weekofyear語(yǔ)法:   weekofyear (string date) 
返回值: int
說(shuō)明: 返回日期在當(dāng)前的周數(shù)。
舉例:
hive>   select weekofyear('2011-12-08 10:03:01') from dual;
49

日期比較函數(shù): datediff語(yǔ)法:   datediff(string enddate, string startdate) 
返回值: int
說(shuō)明: 返回結(jié)束日期減去開(kāi)始日期的天數(shù)。
舉例:
hive>   select datediff('2012-12-08','2012-05-09') from dual;
213

日期增加函數(shù): date_add語(yǔ)法:   date_add(string startdate, int days) 
返回值: string
說(shuō)明: 返回開(kāi)始日期startdate增加days天后的日期。
舉例:
hive>   select date_add('2012-12-08',10) from dual;
2012-12-18

日期減少函數(shù): date_sub語(yǔ)法:   date_sub (string startdate, int days) 
返回值: string
說(shuō)明: 返回開(kāi)始日期startdate減少days天后的日期。
舉例:
hive>   select date_sub('2012-12-08',10) from dual;
2012-11-28

到此,關(guān)于“Hive日期函數(shù)語(yǔ)法介紹”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

分享文章:Hive日期函數(shù)語(yǔ)法介紹
本文鏈接:http://muchs.cn/article16/johogg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、網(wǎng)站改版、網(wǎng)站排名外貿(mào)建站、自適應(yīng)網(wǎng)站動(dòng)態(tài)網(wǎng)站

廣告

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

成都定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)