**:
函式格式
返回值說明
from_unixtime
from_unixtime(bigint unixtime[, string format])
string
轉化unix時間戳(從1970-01-01 00:00:00 utc到指定時間的秒數)到當前時區的時間格式
函式hive (temp)> select from_unixtime(1323308943,'yyyymmdd') from dual;
20111208
hive (temp)> select from_unixtime(1323308943,'yyyy-mm-dd') from dual;
2011-12-08
格式返回值
說明unix_timestamp
unix_timestamp()
bigint
獲得當前時區的unix時間戳
函式hive (temp)> select unix_timestamp() from dual;
1472105939
格式返回值
說明unix_timestamp
unix_timestamp(string date)
bigint
轉換格式為"yyyy-mm-dd hh:mm:ss"的日期到unix時間戳。轉化失敗,則返回0
函式hive (temp)> select unix_timestamp('2016-08-25 13:02:03') from dual;
1472101323
格式返回值
說明unix_timestamp
unix_timestamp(string date, string pattern)
bigint
轉換格式為"yyyymmdd hh:mm:ss"的日期到unix時間戳。轉化失敗,則返回0
函式hive (temp)> select unix_timestamp('20160825 13:02:03','yyyymmdd hh:mm:ss') from dual;
1472101323
格式返回值
說明to_date
to_date(string timestamp)
string
返回日期時間欄位中的日期部分
函式hive (temp)> select to_date('2016-12-08 10:03:01') from dual;
2016-12-08
格式返回值
說明year
year(string date)
int返回日期中的年
函式hive (temp)> select year('2016-12-08 10:03:01') from dual;
2016
hive (temp)> select year('2016-12-08') from dual;
2016
格式返回值
說明month
month(string date)
int返回日期中的月份
函式hive (temp)> select month('2016-12-08 10:03:01') from dual;
12hive (temp)> select month('2016-11-08') from dual;
11
格式返回值
說明day
day(string date)
int返回日期中的天
函式hive (temp)> select day('2016-12-08 10:03:01') from dual;
8hive (temp)> select day('2016-11-18') from dual;
18
格式返回值
說明hour
hour(string date)
int返回日期中的小時
函式hive (temp)> select hour('2016-12-08 10:03:01') from dual;
10
格式返回值
說明minute
minute(string date)
int返回日期中的分鐘
函式hive (temp)> select minute('2016-12-08 10:03:01') from dual;
3
格式返回值
說明second
second(string date)
int返回日期中的秒
函式hive (temp)> select second('2016-12-08 10:03:01') from dual;
1
格式返回值
說明weekofyear
weekofyear(string date)
int返回日期在當前的週數
函式hive (temp)> select weekofyear('2016-12-08 10:03:01') from dual;
49
格式返回值
說明datediff
datediff(string enddate, string startdate)
int返回結束日期減去開始日期的天數
函式hive (temp)> select datediff('2016-12-08','2016-12-02') from dual;
6
格式返回值
說明date_add
date_add(string startdate, int days)
string
返回開始日期startdate增加days天後的日期
函式hive (temp)> select date_add('2016-12-08',10) from dual;
2016-12-18
#當前日期為2016-08-25,在此基礎上加7天
hive (temp)> select date_add(from_unixtime(unix_timestamp(),'yyyy-mm-dd'),7) from dual;
2016-09-01
格式返回值
說明date_sub
date_sub(string startdate, int days)
string
返回開始日期startdate減少days天後的日期
hive (temp)> select date_sub('2016-12-08',10) from dual;
2016-11-28
#當前日期為2016-08-25,在此基礎上減7天
hive (temp)> select date_sub(from_unixtime(unix_timestamp(),'yyyy-mm-dd'),7) from dual;
2016-08-18
hive函式之 日期函式
語法 from unixtime bigint unixtime string format 返回值 string 說明 轉化unix時間戳 從1970 01 01 00 00 00 utc到指定時間的秒數 到當前時區的時間格式 hive selectfrom unixtime 1323308943...
hive當前日期超前 hive函式之 日期函式
1 unix時間戳轉日期函式 from unixtime 語法 from unixtime bigint unixtime string format 返回值 string 說明 轉化unix時間戳 從1970 01 01 00 00 00 utc到指定時間的秒數 到當前時區的時間格式 hive s...
精品整理 hive函式之日期函式大全
語法 from unixtime bigint unixtime string format 返回值 string 說明 轉化unix時間戳 從1970 01 01 00 00 00 utc到指定時間的秒數 到當前時區的時間格式 舉例 hive select from unixtime 132330...