大数据入门到精通15--hive 对 date类型的处理

一。基础日期处理

//date 日期处理
select current_date;
select current_timestamp;
//to_date(time) ;to_date(string)
select to_date(current_timestamp);
select to_date(rental_date) from rental limit 10;
month(date/time)
year(date/time)
day(date/time)
second(time)
minute(time)
hour(time)

select hour("22:32:34.0");
select hour(rental_date),count(hour(rental_date)) counts from rental group by hour(rental_date) order by counts;
//注意order by的字段必须要有名字或者别名
unix_timestamp(timestamp)
from_unixtime(unixtime)

//两种时间格式互转
to_utc_timestamp(timestamp,"EST")
from_utc_timestamp(timestamp,"EST")
//于标准时间之间的互转
select unix_timestamp();
select unix_timestamp(current_timestamp);
select from_unixtime(unix_timestamp(current_timestamp));
select from_utc_timestamp(to_utc_timestamp(current_timestamp,"EST"),"EST"),current_timestamp;

二、高级日期时间格式的处理

//高级的日期功能
datediff(time,time)给出天数差
select datediff("2018-02-02 21:43:32.0","2017-02-02 21:43:32.0");
add_months(time,num)
date_add(time,num)
select add_months(current_timestamp,2);
select date_add(current_timestamp,2);
hive> select add_months(current_timestamp,2);
OK
2019-02-12
Time taken: 0.126 seconds, Fetched: 1 row(s)
hive> select date_add(current_timestamp,2);
OK
2018-12-14
Time taken: 0.123 seconds, Fetched: 1 row(s)
hive>

//日期格式化
date_format(time,"YYYYMMDDHHmmss")
select date_format(current_timestamp,"YYYYMMDDHHmmss")
//支持EE EEEE格式来表示星期

上一篇:Android 切换主题 (二)


下一篇:NFS共享存储的使用