hive时间日期函数及典型场景应用
1、hive取得当前日期时间:
1.1) 取得当前日期:
select current_date();
1.2) 取得当前日期时间:
select current_timestamp();
1.3) hive取得当前时间戳:
select unix_timestamp();
1.4) 时间戳转日期:
select from_unixtime(1517725479,'yyyy-MM-dd HH:dd:ss');
1.5) 日期转unix时间戳:
select to_nuix_timestamp('2017-01-01 12:12:12','yyyy-MM-dd HH:dd:ss');
1.6) hive取得当前时间:
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:dd:ss');
2、hive自动计算其他日期(昨天,今天):
hive中日期加减函数:date_add(start_date,num_days)
2.1) 取得昨天日期:
select date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-1);
select date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),1);
2.2) 取得明天日期:
select date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),1);
select date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-1);
3、hive取得两个日期之间差值(差值为天数):
datediff(date1,date2):date1大于date2,返回值为正,否则,返回值为负。
select datediff(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),-10));
select datediff(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),10));
4、字符串转时间(字符串必须为:yyyy-MM-dd格式)
select to_date('2017-01-01 12:12:12');
5、日期、时间戳、字符串类型格式化输出标准时间格式:
select date_format(current_timestamp(),'yyyy-MM-dd HH:mm:ss');
select date_format(current_date(),'yyyyMMdd');
select date_format('2017-01-01','yyyy-MM-dd HH:mm:ss'); --字符串必须满足yyyy-MM-dd格式
6、utc时间转换:
select from_utc_timestamp(current_timestamp(),8);
select to_utc_timestamp(current_timestamp(),8);
hive时间日期函数及典型场景应用的更多相关文章
- Hive中日期函数总结
--Hive中日期函数总结: --1.时间戳函数 --日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数 select unix_timestamp(); --获得当前时区 ...
- Hive 时间操作函数(转)
1.日期函数UNIX时间戳转日期函数: from_unixtime 语法: from_unixtime(bigint unixtime[, string format]) 返回值: string ...
- SQL-数学、字符串、时间日期函数和类型转换
--数学函数 --ABS绝对值,select ABS(-99)--ceiling取上限,select CEILING(4.5)--floor去下限select FLOOR(4.5)--power 几次 ...
- SQLite中的时间日期函数(转)
SQLite包含了如下时间/日期函数: datetime().......................产生日期和时间date()...........................产生日期tim ...
- PostgreSQL的时间/日期函数使用
PostgreSQL的常用时间函数使用整理如下: 一.获取系统时间函数 1.1 获取当前完整时间 select now(); david=# select now(); now ----------- ...
- SQL servcer 时间日期函数、数据类型转换
1.时间日期函数 2.数据类型转换 3.习题 建立两个表,一个部门表,一个人员表.部门:部门的编号,部门的名称,部门的职责.人员:人员的编号,姓名,年龄,性别,cid所属部门
- [转] PostgreSQL的时间/日期函数使用
PS:http://blog.csdn.net/love_rongrong/article/details/6712883 字符串模糊比较 日期类型的模糊查询是不能直接进行的,要先转换成字符串然后再查 ...
- SQL server 数据库——数学函数、字符串函数、转换函数、时间日期函数
数学函数.字符串函数.转换函数.时间日期函数 1.数学函数 ceiling()--取上限 select ceiling(oil) as 油耗上限 from car floor()--取下限 sele ...
- SQLite中的时间日期函数
SQLite包含了如下时间/日期函数: datetime().......................产生日期和时间 date()...........................产生日期 t ...
随机推荐
- Ubuntu18.04 VMtools的安装与卸载
VM不推荐在Ubuntu中使用VMtools而是open-vm-tools,原文地址https://kb.vmware.com/s/article/2073803 安装方式 1 更新系统源 sudo ...
- Django-DRF-图书增删改查 !!!
自己封装的 class MyResponse(): def __init__(self): self.status = 100 self.msg = None @property def get_ ...
- Oracle内存详解之 Library cache 库缓冲
Oracle内存详解之 Library cache 库缓冲 2017年11月09日 11:38:39 阅读数:410更多 个人分类: 体系结构 Library cache是Shared pool的一部 ...
- 关于strcpy函数形参类型的解析和指针作为输入型输出型参数的不同
在C语言中,字符串一直都是热点,关于strcpy函数大家都很熟悉,但是真正了解的很少,一旦用到总会报一大堆莫名其妙错误,今天我就来给大家详细剖析一下strcpy函数. 虽然不能看到strcpy的内部实 ...
- 在node中使用MongoDB
1.下载安装包,进行安装: https://www.mongodb.com/download-center/community 参考网址:https://www.cnblogs.com/ymwange ...
- python3列表(list)
一.列表(List) 定义:有序的可变的元素集合:通过range函数构造,在python3 中用的时候才会去构造 list = [1,2,3,4,5,'abc',['a',1,2,3],6,7] ...
- Jmeter性能测试之Monitor监控(四)
使用Jmeter(该篇文章使用的版本最高为3.1, 3.1+的版本存在兼容性问题)做性能测试, 要监控服务器硬件资源消耗情况, 可以使用扩展插件完成. 1. 服务端插件下载agent, 点击这里 , ...
- type=file的inpu美化,自定义上传按钮样式
<div class="div1"> <div class="div2">点击上传</div> <input type ...
- 我的Python笔记
声明:本文整理借鉴金角大王的Python之路,Day1 - Python基础1,仅供本人学习使用!!! 本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程 ...
- manjaro安装及设置
因我的笔记本(联想的拯救者)昨晚打开后什么都还没做就被更新系统“抢走”了画面导致按什么都不管用 所以就想起能不能不用win系统,都知道linux比win稳定,so....就找到了manjaro.以下是 ...