hive sql 中时间函数(未完待续)

Part 1 时间戳相关

首先注意时间戳是10位还是13位,13位时间戳是毫秒级别,10位时间戳是秒级别,通常需要的秒级别也就是10位就够了,在这种情况下13位时间戳/1000即可

1.获取当前时间戳

--例如:
select unix_timestamp()   --1565858389

2. 时间转换成时间戳

--输入的时间戳格式必须为'yyyy-MM-dd HH:mm:ss',并且为String类型
select unix_timestamp('2019-08-15 16:40:00')   --1565858400

3.时间戳转换成时间

--例如:
select from_unixtime(1565858389,'yyyy-MM-dd HH:mm:ss')  --2019-08-15 16:39:49
select from_unixtime(1565858389,'yyyy-MM-dd')   --2019-08-15

Part 2 时间 日期提取

获取 年year 月month 日day 时hour 分minute 秒second

select year('2016-12-08 10:03:01');
select month('2016-12-08 10:03:01');
select day('2016-12-08 10:03:01');
select hour('2016-12-08 10:03:01');
select minute('2016-12-08 10:03:01');
select hour('2016-12-08 10:03:01');
select second('2016-12-08 10:03:01');

 获得完整时间的日期部分

select to_date('2021-07-09 11:18:05');
#2021-07-09

Part 3 时间格式转换

16/Mar/2017:12:25:01 +0800-->2017-03-16 12:25:01

select from_unixtime(to_unix_timestamp('16/Mar/2017:12:25:01 +0800', 'dd/MMM/yyy:HH:mm:ss Z'))

20210101-->2021-01-01

(转化成时间戳,时间戳转化成固定格式)

select from_unixtime( unix_timestamp('20210101','yyyyMMdd'),'yyyy-MM-dd')  

Part 4 其他



hive:常见日期函数_ziyin_2013的博客-CSDN博客_hive 日期函数

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值