栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

【hive 日期处理】

【hive 日期处理】

在上篇文章【hive_窗口函数】中学习了hive常见的窗口函数的使用场景及怎么使用,在工作中时间格式的数据也经常会遇到,今天就学习一下,常见的hive时间处理。

1、返回当周的周一
--法1:
    select current_date,date_sub(next_day(current_date,'MO'),7);
--法2:
    select current_date,date_sub(current_date,pmod(datediff(current_date,'1900-01-08'),7));

2、返回当周周五
select current_date,date_sub(current_date,pmod(datediff(current_date,'1900-01-05'),7))

3、日期加减(日、小时、分钟、秒)
select current_date,date_add(substr(current_date,1,10),6);  --当前日期加6天
select current_date,from_unixtime(unix_timestamp(current_date)+43200,'yyyy-MM-dd HH:mm:ss')  --12h=43200s:12*60*60,5m=300s:5*60
--mysql:
    select date_add(substr(current_date,1,10),interval 6 day);

4、时间差(日)
select datediff('2020-07-24 11:42:58','2020-07-23 15:01:13')

5、时间戳转化成时间
--10位时间戳
    select from_unixtime(1595487673,'yyyy-MM-dd HH:mm:ss')
--13位时间戳
    select from_unixtime(cast(1595487673343/1000 as int),'yyyy-MM-dd HH:mm:ss')


6、日期转化成时间戳
--10位时间戳
    select unix_timestamp(cast('2020-07-23 15:01:13' as timestamp))
--13位时间戳
    select unix_timestamp(cast(substr('2020-07-23 15:01:13.343', 1, 19) as timestamp)) * 1000 + cast(substr('2020-07-23 15:01:13.343', 21) as bigint)


详细内容请看我公众号~

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/708151.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号