hive中常用的日期表达方式

12 篇文章 2 订阅

注意 MM,DD,MO,TU 等要大写

Hive 可以在 where 条件中使用 case when

已知日期要求日期语句结果
本周任意一天本周一select date_sub(next_day(‘2016-11-29’,‘MO’),7) ;2016-11-28
本周任意一天上周一select date_sub(next_day(‘2016-11-29’,‘MO’),14) ;2016-11-21
本周任意一天本周二select date_sub(next_day(‘2016-11-29’,‘MO’),6)2016-11-29
本周任意一天上周二select date_sub(next_day(‘2016-11-29’,‘MO’),13) ;2016-11-22
本周任意一天上周末select date_sub(next_day(‘2016-11-29’,‘MO’),8) ;2016-11-27
本月任意一天上月末select date_sub(trunc(‘2016-11-02’,‘MM’),1);2016-10-31
本月任意一天上月初select trunc(add_months(‘2016-11-02’,-1),‘MM’)2016-10-01
本月任意一天本月初select trunc(‘2016-11-02’,‘MM’)2016-11-01
本月任意一天上上月26select date_add(add_months(trunc(‘2016-11-02’,‘MM’),-2),25) ;2016-09-26
本月任意一天上月26select date_add(add_months(trunc(‘2016-11-02’,‘MM’),-1),25) ;2016-10-26
当前时间戳select current_timestamp() ;2016-11-30 15:18:06.276
当前时间select current_date() ;2016-11-30
本季度任意一天上季度初case quarter(‘2016-05-23’) when 1 then concat(year(‘2016-05-23’)-1,’-10-01’) when 2 then concat(year(‘2016-05-23’),’-01-01’) when 3 then concat(year(‘2016-05-23’),’-04-01’) when 4 then concat(year(‘2016-05-23’),’-07-01’) end 或 add_months(concat(year(‘2017-02-23’),’-’,substr(concat(‘0’,quarter(‘2017-02-23’)*3+1),-2),’-01’),-6)
本季度任意一天本季度初case quarter(‘2016-05-23’) when 1 then concat(year(‘2016-05-23’),’-01-01’) when 2 then concat(year(‘2016-05-23’),’-04-01’) when 3 then concat(year(‘2016-05-23’),’-07-01’) when 4 then concat(year(‘2016-05-23’),’-10-01’) end 或add_months(concat(year(‘2017-02-23’),’-’,substr(concat(‘0’,quarter(‘2017-02-23’)*3+1),-2),’-01’),-3)
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

扫地增

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值