Hive的日期函数汇总(大多数MySQL也能用)

常用日期函数:

unix_timestamp

unix_timestamp:返回当前或指定时间的时间戳

select unix_timestamp();
select unix_timestamp("2020-10-28",'yyyy-MM-dd'); #MySQL不好使

from_unixtime

from_unixtime:将时间戳转为日期格式

select from_unixtime(1603843200);

current_date

current_date:当前日期

select current_date;

current_timestamp

current_timestamp:当前的日期加时间

select current_timestamp;

to_date

to_date:抽取日期部分

select to_date('2020-10-28 12:12:12'); #MySQL 用不了

year

year:获取年

select year('2020-10-28 12:12:12');

month

month:获取月

select month('2020-10-28 12:12:12');

day

day:获取日

select day('2020-10-28 12:12:12');

hour

hour:获取时

select hour('2020-10-28 12:12:12');

minute

minute:获取分

select minute('2020-10-28 12:12:12');

second

second:获取秒

select second('2020-10-28 12:12:12');

weekofyear

weekofyear:当前时间是一年中的第几周

select weekofyear('2020-10-28 12:12:12');

dayofmonth

dayofmonth:当前时间是一个月中的第几天

select dayofmonth('2020-10-28 12:12:12');

months_between

months_between: 两个日期间的月份

select months_between('2020-04-01','2020-10-28'); #MySQL用不了

add_months

add_months:日期加减月

select add_months('2020-10-28',-3); #MySQL用不了

datediff

datediff:两个日期相差的天数

select datediff('2020-11-04','2020-10-28');

date_add

date_add:日期加天数

select date_add('2020-10-28',4); #MySQL用不了

date_sub

date_sub:日期减天数

select date_sub('2020-10-28',-4);  #MySQL用不了

last_day

last_day:日期的当月的最后一天

select last_day('2020-02-30');

date_format

date_format(): 格式化日期

select date_format('2020-10-28 12:12:12','yyyy/MM/dd HH:mm:ss'); #hive
select date_format('2020-10-28 12:12:12','2020/10/20 12:12:12'); #mysql 
select date_format('2021-10-10 12:46:48','yyyy mm');
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值