Hive 之 日期函数
来源:互联网 发布:2017双11淘宝交易额 编辑:程序博客网 时间:2024/05/16 03:39
转自:http://www.jianshu.com/p/e30395941f9c
1、日期函数UNIX时间戳转日期函数:from_unixtime()
hive (temp)> select from_unixtime(1323308943,'yyyyMMdd') from dual;20111208hive (temp)> select from_unixtime(1323308943,'yyyy-MM-dd') from dual;2011-12-08
2、当前UNIX时间戳函数: unix_timestamp()
2.1 获取当前UNIX时间戳函数
hive (temp)> select unix_timestamp() from dual;1472105939
2.2 日期转UNIX时间戳函数
hive (temp)> select unix_timestamp('2016-08-25 13:02:03') from dual;1472101323
2.3 指定格式日期转UNIX时间戳函数
hive (temp)> select unix_timestamp('20160825 13:02:03','yyyyMMdd HH:mm:ss') from dual;1472101323
3、日期时间转日期函数: to_date()
hive (temp)> select to_date('2016-12-08 10:03:01') from dual;2016-12-08
4、日期转年函数: year()
hive (temp)> select year('2016-12-08 10:03:01') from dual;2016hive (temp)> select year('2016-12-08') from dual;2016
5、日期转月函数: month()
hive (temp)> select month('2016-12-08 10:03:01') from dual;12hive (temp)> select month('2016-11-08') from dual;11
6、日期转天函数: day()
hive (temp)> select day('2016-12-08 10:03:01') from dual;8hive (temp)> select day('2016-11-18') from dual;18
7、日期转小时函数: hour()
hive (temp)> select hour('2016-12-08 10:03:01') from dual;10
8、日期转分钟函数: minute()
hive (temp)> select minute('2016-12-08 10:03:01') from dual;3
9、日期转秒函数: second()
hive (temp)> select second('2016-12-08 10:03:01') from dual;1
10、日期转周函数: weekofyear()
hive (temp)> select weekofyear('2016-12-08 10:03:01') from dual;49
11、日期比较函数: datediff(string enddate, string startdate)
hive (temp)> select datediff('2016-12-08','2016-12-02') from dual;6
12、日期增加函数: date_add(string startdate, int 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
13、日期减少函数:date_sub (string startdate, int 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
作者:一刀Q
链接:http://www.jianshu.com/p/e30395941f9c
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
阅读全文
0 0
- Hive 之 日期函数
- Hive学习之内置数学、日期函数
- hive日期函数
- hive 日期函数小结
- Hive日期函数
- Hive 日期函数 weekofyear
- HIVE日期函数
- [HIve]日期相关函数
- hive日期函数
- [转载]Hive日期函数
- hive日期函数 整理
- Hive(八)--日期函数
- hive日期函数总结
- Hive 日期函数
- Hive --- 日期函数
- Hive日期函数
- Hive日期函数
- Hive常用日期函数整理
- html+css+javascript代码编程规范之HTML
- Spring cloud eureka 简单例子
- Android 内存
- hbase根据rowKey范围批量删除
- composer 学习小结
- Hive 之 日期函数
- CSS3设置Border边框是内边框还是外边框
- C语言:最长上升子序列LIS算法实现
- bootstrap 手风琴 (jq添加icon)
- SUST2017迎新赛答案
- Python 装饰器
- js高级知识---词法分析和AO 链
- 3、米斯特白帽子WEB安全攻防培训-第三方风险-[域名商、IDC、外域JS]
- MyBatis+oracle 批量插入数据的一些问题