前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >2018-04-28 hive 常用的日期函数

2018-04-28 hive 常用的日期函数

作者头像
大数据工程师-公子
发布2019-03-14 15:46:57
2.4K0
发布2019-03-14 15:46:57
举报

先看代码

## 当前日期和时间
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 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');

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年04月28日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 先看代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档