hive 时间函数 总结
来源:互联网 发布:mapreduce排序算法 编辑:程序博客网 时间:2024/06/03 10:06
大数据,算法qq交流群:397173819
做数据挖掘的,离不开使用各种时间函数。
为了避免遗忘,以及后续各种抓瞎到处乱找,特意总结了hive中大部分常用的时间函数,方便自己也方便他们。
1.unix_timestamp()
返回当前时区的unix时间戳
返回类型:bigint
hive (tmp)> select unix_timestamp() from hive_sum limit 1;
1465875016
2.from_unixtime(bigint unixtime[,string format])
时间戳转日期函数
返回类型:string
hive (tmp)> select from_unixtime(unix_timestamp(),’yyyyMMdd’) from hive_sum limit 1;
20160614
3.unix_timestamp(string date)
返回指定日期格式的的时间戳
返回类型:bigint
注意:如果后面只有date参数,date的形式必须为’yyyy-MM-dd HH:mm:ss’的形式。
hive (tmp)> select unix_timestamp(‘2016-06-01’) from hive_sum limit 1;
NULL
hive (tmp)> select unix_timestamp(‘2016-06-01 00:00:00’) from hive_sum limit 1;
1464710400
4.unix_timestamp(string date,string pattern)
返回指定日期格式的时间戳
返回类型:bigint
hive (tmp)> select unix_timestamp(‘2016-06-01’,’yyyyMMdd’) from hive_sum limit 1;
1449331200
5.to_date(string date)
返回时间字段中的日期部分
返回类型:string
hive (tmp)> select to_date(‘2016-06-01 00:00:00’) from hive_sum limit 1;
2016-06-01
6.year(string date)
返回时间字段中的年
返回类型:int
hive (tmp)> select year(‘2016-06-01 00:00:00’) from hive_sum limit 1;
2016
7.month(string date)
返回时间字段中的月
返回类型:int
hive (tmp)> select month(‘2016-06-01’) from hive_sum limit 1;
6
8.day(string date)
返回时间字段中的天
返回类型:int
hive (tmp)> select day(‘2016-06-01’) from hive_sum limit 1;
1
9.weekofyear(string date)
返回时间字段是本年的第多少周
返回类型:int
hive (tmp)> select weekofyear(‘2016-06-01’) from hive_sum limit 1;
22
10.datediff(string enddate,string begindate)
返回enddate与begindate之间的时间差的天数
返回类型:int
hive (tmp)> select datediff(‘2016-06-01’,’2016-05-01’) from hive_sum limit 1;
31
11.date_add(string date,int days)
返回date增加days天后的日期
返回类型:string
hive (tmp)> select date_add(‘2016-06-01’,15) from hive_sum limit 1;
2016-06-16
12.date_sub(string date,int days)
返回date减少days天后的日期
返回类型:string
hive (tmp)> select date_sub(‘2016-06-01’,15) from hive_sum limit 1;
2016-05-17
- hive 时间函数 总结
- hive时间函数总结
- hive 时间处理函数
- hive时间函数转换
- HIVE 时间操作函数
- hive- 时间操作函数
- hive 时间函数
- hive时间操作函数
- hive时间操作函数
- hive时间函数
- Hive时间处理函数
- hive时间函数
- HIVE时间函数小结
- hive---group_concat()函数总结
- Hive窗口函数总结
- hive日期函数总结
- hive常用函数总结
- hive函数总结
- 苹果最新审核标准:IPv6
- js关于两种垃圾回收的机制
- UBUNTU修改root初始化 密码
- 资源文件相关学习总结
- [ios]scrollView实现移动与缩放
- hive 时间函数 总结
- Unsupported major.minor version 51.0解决办法
- ubuntu搭建ssh服务器,实现ssh免密码登录
- springMVC中两种validation的简单使用
- 科学计算:Python ----线性代数基础
- nyoj 124 中位数 【水,nth_element()练习】
- 数据结构概念
- saiku二次开发pom文件
- UITextView的使用