hive常用日期函数

工作原因有时候需要使用到hive的日期函数,但是很多东西都记不住,每次网上去找又浪费时间,干脆自己整理一个。

  • 获取日期

    select current_date(); --返回2021-04-26
    
  • 获取时间戳

    # 单位:秒 返回bigint
    select unix_timestamp(); --返回1619401695
    
  • 获取日期时间

    select current_timestamp(); --返回2021-04-25 19:48:43.153
    
  • 格式化时间戳

    select from_unixtime(1619351633,'yyyy-MM-dd') --返回结果 2021-04-25
    
    select from_unixtime(1590681600,'yyyyMMdd') --返回结果 20210425
     
    select from_unixtime(1590729143,'yyyy-MM-dd HH:mm:ss') --返回结果 2021-04-25 19:53:53
     
    select from_unixtime(1590729143) --返回结果 --2021-04-25 19:53:53 不加默认 yyyy-MM-dd HH:mm:ss 格式
     
    select from_unixtime(unix_timestamp('2021-04-25','yyyy-MM-dd'),'Y年') --返回结果 2021年
     
    select from_unixtime(unix_timestamp('2021-04-25','yyyy-MM-dd'),'yyyy-MM') --返回结果 2021-04
     
    select from_unixtime(unix_timestamp('20210425','yyyyMMdd'),'yyyy-MM-dd')  --返回结果 2021-04-25
     
    select from_unixtime(unix_timestamp('2021-04-25','yyyy-MM-dd'),'EEEE') --返回结果 Sunday
     
    select from_unixtime(unix_timestamp('2021-04-25','yyyy-MM-dd'),'w') --返回第几周(18)
     
    select from_unixtime(unix_timestamp('2021-04-25','yyyy-MM-dd'),'u') -- 返回本周的第几天(7)
     
    select from_unixtime(unix_timestamp('2021-04-25','yyyy-MM-dd'),'D') -- 本年的第几天(115)
     
    select from_unixtime(unix_timestamp('2021-04-25','yyyy-MM-dd'),'d') -- 本月的第几天(25)
    
  • 日期转时间戳

    # 参数时可选的,当参数为空时,返回当前Unix是时间戳,精确到秒。可以指定一个具体的日期,转换为Unix时间戳格式
    # unix_timestamp(string datetime,string format)
    # 日期时间
    <
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值