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 ...
随机推荐
- python结合pyvmomi批量关闭vmware虚拟机
#!/usr/bin/env python #参考https://github.com/vmware/pyvmomi/blob/master/sample/poweronvm.py "&qu ...
- 【原创】大叔问题定位分享(28)openssh升级到7.4之后ssh跳转异常
服务器集群之间忽然ssh跳转不通 # ssh 192.168.0.1The authenticity of host '192.168.0.1 (192.168.0.1)' can't be esta ...
- python使用stomp连接activemq
一.安装ActiveMQ服务 1. 当使用windows时,安装参考:https://blog.csdn.net/WuLex/article/details/78323811 启动:运行activem ...
- MySQL视图,函数,触发器,存储过程
1. 视图 视图是一个虚拟表,它的本质是根据SQL语句获取动态的数据集,并为其命名,用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的临时表摘出来, ...
- gflags_static.lib 无法解析的外部符号 __imp__PathMatchSpec
在用gflags库时生成提示 无法解析的外部符号 __imp__PathMatchSpec 解决办法:Add "shlwapi.lib" to "Project - ...
- Redis数据结构之intset
本文及后续文章,Redis版本均是v3.2.8 上篇文章<Redis数据结构之robj>,我们说到redis object数据结构,其有5中数据类型:OBJ_STRING,OBJ_LIST ...
- Python学习(三十三)—— Django之ORM
Object Relational Mapping(ORM) 一.ORM介绍 ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系 ...
- Codeforces 1045E. Ancient civilizations 构造 计算几何 凸包
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1045E.html 4K码量构造题,CF血腥残暴! 题解 首先,如果所有点颜色相同,那么直接连个菊花搞定. ...
- CodeForces 630G Challenge Pennants (组合数学)
<题目链接> 题目大意: 有两种旗子,分别有5个和3个,将这些旗子分配给n个人,有多少中方法. 解题分析: 5面A旗子的发放方案为:$[1,1,1,1,1],[1,1,1,2],[1,2, ...
- Aspnet Mvc 前后端分离项目手记(三)关于restful 风格Url设计
RESTful 不是新东西,简单理解它的核心思想就是最大程度的利用http协议的一些特点,比如uri,比如请求动词,在前后端分离的项目中会有大大的好处 ,好的设计的url简单明了,胜过详细的说明文档. ...