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