hive常用的日期函数(转载)

转载: hive常用的日期函数

## 当前日期和时间
SELECT current_timestamp();
-- 2018-04-28 11:46:03.136

## 获取当前日期,当前是 2018-04-28
SELECT current_date;
OR
SELECT current_date();
-- 2018-04-28

## 获取unix系统下的时间戳
SELECT UNIX_TIMESTAMP();
-- 1524884881

## 当前是 2018-04-28
select substr(current_timestamp, 0, 10);
-- 2018-04-28

## 当前是 2018-04-28
select date_sub(current_date, 1);
-- 2018-04-27

## yyyy-MM-dd HH:MM:ss 截取日期
select to_date("2017-10-22 10:10:10");
-- 2017-10-22
select date_format("2017-10-22" "yyyy-MM")
-- 2017-10

## 两个日期之间的天数差
select datediff("2017-10-22", "2017-10-12");
-- 10

select datediff("2017-10-22 10:10:10", "2017-10-12 23:10:10");
-- 10

select datediff("2017-10-22 01:10:10", "2017-10-12 23:10:10");
-- 10

## 时间截取
select from_unixtime(cast(substr("1504684212155", 0,10) as int)) dt;
-- 2017-09-06 15:50:12

## 时间戳转日期
## 语法: to_date(string timestamp)
select to_date(from_unixtime(UNIX_TIMESTAMP()));
-- 2018-04-28

select FROM_UNIXTIME(UNIX_TIMESTAMP(),'yyyy-MM-dd 10:30:00');
-- 2018-04-28 10:30:00

select concat(date_sub(current_date,1),' 20:30:00');
-- 2018-04-27 20:30:00

-- hive version 1.2.0
select date_format(date_sub(current_date,1),'yyyy-MM-dd 20:30:00');
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值