Hive的日期函數

來源:互聯網
上載者:User

標籤:hive   日期   timestamp   

1.unix時間戳記轉時間函數
文法: from_unixtime(bigint unixtime[, string format])傳回值: string說明: 轉化UNIX時間戳記(從1970-01-01 00:00:00 UTC到指定時間的秒數)到當前時區的時間格式舉例:hive> select from_unixtime(1323308943,‘yyyyMMdd’) from dual;20111208
2.擷取當前時區的unix時間戳記
文法: unix_timestamp()傳回值: bigint說明: 獲得當前時區的UNIX時間戳記舉例:hive> select unix_timestamp() from dual;1323309615

3.時間轉unix時間戳記
日期轉UNIX時間戳記函數: unix_timestamp文法:   unix_timestamp(string date)傳回值:   bigint說明: 轉換格式為“yyyy-MM-dd HH:mm:ss“的日期到UNIX時間戳記。如果轉化失敗,則返回0。舉例:hive>   select unix_timestamp(’2011-12-07 13:01:03′) from dual;1323234063
指定格式日期轉UNIX時間戳記函數: unix_timestamp文法:   unix_timestamp(string date, string pattern)傳回值:   bigint說明: 轉換pattern格式的日期到UNIX時間戳記。如果轉化失敗,則返回0。舉例:hive>   select unix_timestamp(’20111207 13:01:03′,’yyyyMMdd HH:mm:ss’) from dual;1323234063


4.日期時間轉日期函數
文法: to_date(string timestamp)傳回值: string說明: 返回日期時間欄位中的日期部分。舉例:hive> select to_date(’2011-12-08 10:03:01′) from dual;2011-12-08

5.擷取年份的函數
文法: year(string date)傳回值: int說明: 返回日期中的年。舉例:hive> select year(’2011-12-08 10:03:01′) from dual;2011hive> select year(’2012-12-08′) from dual;2012

6.擷取月份的函數
文法: month (string date)傳回值: int說明: 返回日期中的月份。舉例:hive> select month(’2011-12-08 10:03:01′) from dual;12hive> select month(’2011-08-08′) from dual;8

7.擷取天的函數
文法: day (string date)傳回值: int說明: 返回日期中的天。舉例:hive> select day(’2011-12-08 10:03:01′) from dual;8hive> select day(’2011-12-24′) from dual;24

8.擷取小時的函數
文法: hour (string date)傳回值: int說明: 返回日期中的小時。舉例:hive> select hour(’2011-12-08 10:03:01′) from dual;10

9.擷取分數的函數
文法: minute (string date)傳回值: int說明: 返回日期中的分鐘。舉例:hive> select minute(’2011-12-08 10:03:01′) from dual;3

10.擷取秒的函數
文法: second (string date)傳回值: int說明: 返回日期中的秒。舉例:hive> select second(’2011-12-08 10:03:01′) from dual;1
11.擷取日期在當前的周數
文法: weekofyear (string date)傳回值: int說明: 返回日期在當前的周數。舉例:hive> select weekofyear(’2011-12-08 10:03:01′) from dual;49


12.日期比較函數
文法: datediff(string enddate, string startdate)傳回值: int說明: 返回結束日期減去開始日期的天數。舉例:hive> select datediff(’2012-12-08′,’2012-05-09′) from dual;213

13.日期增加函數
文法: date_add(string startdate, int days)傳回值: string說明: 返回開始日期startdate增加days天后的日期。舉例:hive> select date_add(’2012-12-08′,10) from dual;2012-12-18

14.日期減少函數
文法: date_sub (string startdate, int days)傳回值: string說明: 返回開始日期startdate減少days天后的日期。舉例:hive> select date_sub(’2012-12-08′,10) from dual;2012-11-28

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.