時(shí)間語(yǔ)句的用法

日期函數(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;

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、關(guān)系運(yùn)算: 1. 等值比較: = 語(yǔ)法:A=B 操作類型:所有基本類型 描述:如果表達(dá)式A與表達(dá)式B相等,則為...
    起個(gè)什么呢稱呢閱讀 1,252評(píng)論 0 2
  • Hive函數(shù) Hive函數(shù) 一、關(guān)系運(yùn)算: 等值比較: = 語(yǔ)法:A=B操作類型:所有基本類型描述:如果表達(dá)式A與...
    依天立業(yè)閱讀 1,129評(píng)論 0 8
  • 日期函數(shù)UNIX時(shí)間戳轉(zhuǎn)日期函數(shù): from_unixtime語(yǔ)法: from_unixtime(bigint...
    485b1aca799e閱讀 4,515評(píng)論 0 0
  • pyspark.sql模塊 模塊上下文 Spark SQL和DataFrames的重要類: pyspark.sql...
    mpro閱讀 9,912評(píng)論 0 13
  • 沒(méi)有什么比眼淚更能去感動(dòng)一個(gè)人,也許只有眼淚,能將我們所受的委屈和隱忍的苦楚一并釋放出來(lái)。 傷感無(wú)處不在,猶如那漫...
    四夕白水閱讀 690評(píng)論 0 0

友情鏈接更多精彩內(nèi)容