hive時間操作函數

來源:互聯網
上載者:User
hive時間操作函數 標籤: hive函數linux 2016-12-21 16:07  49人閱讀  評論(0)  收藏  舉報   分類: hive

日期函數UNIX時間戳記轉日期函數: from_unixtime文法:   from_unixtime(bigint unixtime[, string format])

傳回值: string

說明: 轉化UNIX時間戳記(從1970-01-01 00:00:00 UTC到指定時間的秒數)到當前時區的時間格式

舉例:

Hive>   select from_unixtime(1323308943,’yyyyMMdd’) from dual;

20111208

擷取當前UNIX時間戳記函數: unix_timestamp文法:   unix_timestamp()

傳回值:   bigint

說明: 獲得當前時區的UNIX時間戳記

舉例:

hive>   select unix_timestamp() from dual;

1323309615

日期轉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

日期時間轉日期函數: to_date文法:   to_date(string timestamp)

傳回值:   string

說明: 返回日期時間欄位中的日期部分。

舉例:

hive>   select to_date(’2011-12-08 10:03:01′) from dual;

2011-12-08

日期轉年函數: year文法:   year(string date)

傳回值: int

說明: 返回日期中的年。

舉例:

hive>   select year(’2011-12-08 10:03:01′) from dual;

2011

hive>   select year(’2012-12-08′) from dual;

2012

日期轉月函數: month文法: month   (string date)

傳回值: int

說明: 返回日期中的月份。

舉例:

hive>   select month(’2011-12-08 10:03:01′) from dual;

12

hive>   select month(’2011-08-08′) from dual;

8

日期轉天函數: day文法: day   (string date)

傳回值: int

說明: 返回日期中的天。

舉例:

hive>   select day(’2011-12-08 10:03:01′) from dual;

8

hive>   select day(’2011-12-24′) from dual;

24

日期轉小時函數: hour文法: hour   (string date)

傳回值: int

說明: 返回日期中的小時。

舉例:

hive>   select hour(’2011-12-08 10:03:01′) from dual;

10

日期轉分鐘函數: minute文法: minute   (string date)

傳回值: int

說明: 返回日期中的分鐘。

舉例:

hive>   select minute(’2011-12-08 10:03:01′) from dual;

3

日期轉秒函數: second文法: second   (string date)

傳回值: int

說明: 返回日期中的秒。

舉例:

hive>   select second(’2011-12-08 10:03:01′) from dual;

1

日期轉周函數: weekofyear文法:   weekofyear (string date)

傳回值: int

說明: 返回日期在當前的周數。

舉例:

hive>   select weekofyear(’2011-12-08 10:03:01′) from dual;

49

日期比較函數: datediff文法:   datediff(string enddate, string startdate)

傳回值: int

說明: 返回結束日期減去開始日期的天數。

舉例:

hive>   select datediff(’2012-12-08′,’2012-05-09′) from dual;

213

日期增加函數: date_add文法:   date_add(string startdate, int days)

傳回值: string

說明: 返回開始日期startdate增加days天后的日期。

舉例:

hive>   select date_add(’2012-12-08′,10) from dual;

2012-12-18

日期減少函數: date_sub文法:   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.