hive时间函数

本文详细介绍了Hive中常用的日期处理函数,包括如何转换日期格式、获取时间戳、计算日期差等操作。通过具体示例展示了如何使用这些函数解决实际问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

hive (dwd)> select unix_timestamp();--select current_timestamp();
1616338251

hive (dwd)> select unix_timestamp('2021-03-21 22:50:51');
1616338251

hive (dwd)> select unix_timestamp('2021-03-21', 'yyyy-MM-dd');
1616256000

hive (dwd)> select from_unixtime(1616256000);
2021-03-21 00:00:00

hive (dwd)> select from_unixtime(1616256000, 'yyyy-MM-dd');
2021-03-21

hive (dwd)> select datediff('2021-03-21', '1970-01-01');
18707

hive (dwd)> select date_add('2021-03-21', 1);
2021-03-22

hive (dwd)> select date_add('2021-03-21', -1);
2021-03-20

hive (dwd)> select date_sub('2021-03-21', 1);
2021-03-20

hive (dwd)> select date_sub('2021-03-21', -1);
2021-03-22

hive (dwd)> select datediff('2021-03-21', '2021-03-22');
-1

 

1.yyyyMMdd转yyyy-MM-dd
from_unixtime(unix_timestamp('20190129', 'yyyyMMdd'), 'yyyy-MM-dd');

2.yyyy-MM-dd转yyyyMMdd
select from_unixtime(unix_timestamp('2019-01-29', 'yyyy-MM-dd'), 'yyyyMMdd');
select regexp_replace('2019-01-29', '-', '');
select date_format('2019-01-29', 'yyyyMMdd');

3.timestamp转yyyy-MM-dd
select from_unixtime(1616256000, 'yyyy-MM-dd');

4.yyyy-MM-dd转timestamp
select to_unix_timestamp('2019-09-10', 'yyyy-MM-dd');

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值