千家信息网

hive时间日期函数怎么用

发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,小编给大家分享一下hive时间日期函数怎么用,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!1、hive取得当前日期时间:1.1) 取得当前日期:select current_date
千家信息网最后更新 2026年11月03日hive时间日期函数怎么用

小编给大家分享一下hive时间日期函数怎么用,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

1、hive取得当前日期时间:

1.1) 取得当前日期:
select current_date();

1.2) 取得当前日期时间:
select current_timestamp();

1.3) hive取得当前时间戳:
select unix_timestamp();

1.4) 时间戳转日期:
select from_unixtime(1517725479,'yyyy-MM-dd HH:dd:ss');

1.5) 日期转unix时间戳:
select to_nuix_timestamp('2017-01-01 12:12:12','yyyy-MM-dd HH:dd:ss');

1.6) hive取得当前时间:
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:dd:ss');

2、hive自动计算其他日期(昨天,今天):

hive中日期加减函数:date_add(start_date,num_days)

2.1) 取得昨天日期:

select date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-1);
select date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),1);

2.2) 取得明天日期:

select date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),1);
select date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-1);

3、hive取得两个日期之间差值(差值为天数):

datediff(date1,date2):date1大于date2,返回值为正,否则,返回值为负。

select datediff(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-10));
select datediff(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),10));

4、字符串转时间(字符串必须为:yyyy-MM-dd格式)

select to_date('2017-01-01 12:12:12');

5、日期、时间戳、字符串类型格式化输出标准时间格式:

select date_format(current_timestamp(),'yyyy-MM-dd HH:mm:ss');

select date_format(current_date(),'yyyyMMdd');

select date_format('2017-01-01','yyyy-MM-dd HH:mm:ss'); --字符串必须满足yyyy-MM-dd格式

6、utc时间转换:

select from_utc_timestamp(current_timestamp(),8);

select to_utc_timestamp(current_timestamp(),8);

看完了这篇文章,相信你对"hive时间日期函数怎么用"有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!

日期 时间 字符 字符串 格式 函数 差值 篇文章 两个 之间 天数 完了 更多 标准 标准时 知识 类型 行业 资讯 资讯频道 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 科技互联网 广东万易互联网科技有限公司惠州分公司 互联网最新的科技 金融科技创新监管互联网金融 以房互联网科技 贷财互联网科技 互联网科技ppt模板 互联网科技公司介绍 太原新华互联网科技学校怎么样 深圳互联网科技怎么样 移动互联网科技股 互联网为啥属于高科技 互联网新科技动漫ppt素材 济南有互联网科技公司吗 恒生互联网科技业指数调整周期 互联网金融科技元年 珠海东科互联网科技有限公司 互联网科技平台产品运营 互联网科技创新创业项目 数字科技和互联网金融哪个好 狮子座互联网科技有限公司 科技互联网创业计划书 以后互联网后是啥科技 移动互联网科技股 厦门比较好的科技互联网公司 本届互联网博览会上的黑科技 中国互联网公司排名锤子科技 广州有谷有贝互联网科技有限公司 萌小萌互联网科技河南有限公司 互联网大会出现的黑科技
0