1.日期函數 to_date(string expr)express
返回類型:stringide
描述:返回時間字符串日期部分函數
to_date(expr) - Extracts the date part of the date or datetime expression exprspa
實例:orm
hive> select to_date('2014-09-16 15:50:08.119') from default.dual;字符串
2014-09-16string
2.年份函數 year(string expr)it
返回類型:intio
描述:返回時間字符串年份數字date
year(date) - Returns the year of date
實例:
hive> select year('2014-09-16 15:50:08.119') from default.dual;
2014
3.月份函數 month(string expr)
返回類型:int
描述:返回時間字符串月份數字
month(date) - Returns the month of date
實例:
hive> select month('2014-09-16 15:50:08.119') from default.dual;
09
4.天函數 day(string expr)
返回類型:int
描述:返回時間字符串的天
day(date) - Returns the date of the month of date
實例:
hive> select day('2014-09-16 15:50:08.119') from default.dual;
16
5.小時函數 hour(string expr)
返回類型:int
描述:返回時間字符串小時數字
hour(date) - Returns the hour of date
實例:
hive> select hour('2014-09-16 15:50:08.119') from default.dual;
15
6.分鐘函數 hour(string expr)
返回類型:int
描述:返回時間字符串分鐘數字
minute(date) - Returns the minute of date
實例:
hive> select minute('2014-09-16 15:50:08.119') from default.dual;
50
7.秒函數 second(string expr)
返回類型:int
描述:返回時間字符串分鐘數字
second(date) - Returns the second of date
實例:
hive> select second('2014-09-16 15:50:08.119') from default.dual;
08
8.日期增長函數 date_add(start_date, num_days)
返回類型:string
描述:返回增長num_days 天數的日期(負數則爲減小)
date_add(start_date, num_days) - Returns the date that is num_days after start_date.
實例:
hive>select date_add('2014-09-16 15:50:08.119',10) from default.dual;
2014-09-26
hive>select date_add('2014-09-16 15:50:08.119',-10) from default.dual;
2014-09-06
9.日期減小函數 date_sub(start_date, num_days)
返回類型:string
描述:返回num_days 天數以前的日期(負數則爲增長)
date_sub(start_date, num_days) - Returns the date that is num_days before start_date.
實例:
hive>select date_sub('2014-09-16 15:50:08.119',10) from default.dual;
2014-09-06
hive>select date_sub('2014-09-16 15:50:08.119',-10) from default.dual;
2014-09-26
10.周期函數 weekofyear(start_date, num_days)
返回類型:int
描述:返回當前日期位於本年的週期 一週一個週期
weekofyear(date) - Returns the week of the year of the given date. A week is considered to start on a Monday and week 1 is the first week with >3 days.
實例:
hive>select weekofyear('2014-09-16 15:50:08.119') from default.dual;
38
11.日期比較函數 weekofyear(start_date, num_days)
返回類型:string
描述:返回2個時間的日期差
datediff(date1, date2) - Returns the number of days between date1 and date2
date1-date2
實例:
hive>select datediff('2014-09-16 15:50:08.119','2014-09-15') from default.dual;