hive 常见时间日期函数的使用
1.时间戳函数
日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数
获得当前时区的UNIX时间戳: select unix_timestamp(); 1533716607
将指定的时间转为UNIX时间戳 :select unix_timestamp('2018-08-08 16:22:01'); 1533716521
将指定的时间转为UNIX时间戳: select unix_timestamp('2018-08-08 16:22:01','yyyy-MM-dd HH:mm:ss'); 1533716521
select unix_timestamp('2018-08-08 16:22:01','yyyyMMdd HH:mm:ss'); 1533716521 --将指定的时间转为UNIX时间戳
2.时间戳转日期
select from_unixtime(1533716521); 2018-08-08 16:22:01
select from_unixtime(1533716521,'yyyyMMdd'); 20180808
select from_unixtime(1533716521,'yyyy-MM-dd HH:mm:ss'); 2018-08-08 16:22:01
获取系统当前时间 :
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'); 2018-08-08 16:28:21
日期转换为其他格式的日期:
select from_unixtime(unix_timestamp('2018-08-08 16:28:21',yyyy-MM-dd HH:mm:ss'),'yyyyMMdd'); 20180808
3.获取当前日期: current_date
select current_date ;2018-08-08
4.日期时间转日期:to_date(string timestamp)
select to_date('2018-08-08 17:12:00') ;2018-08-08
分区参数转日期:
to_date(from_unixtime(unix_timestamp('${dt}','yyyyMMdd')))
分区参数当月第一天日期:
to_date(from_unixtime(unix_timestamp(concat(substr('${dt}',1,6),'01'),'yyyyMMdd')))
5.计算两个日期之间的天数: datediff
select datediff('2018-08-08','2018-08-01') ; 7
6.日期增加和减少: date_add/date_sub(string startdate,int days)
select date_add('2018-08-04',1) , date_sub('2018-08-04',1) ; 2018-08-05 2018-08-03
7.其他日期函数
查询当前系统时间(包括毫秒数):` current_timestamp;
查询当月第几天: dayofmonth(current_date);
月末: last_day(current_date)
当月第1天: date_sub(current_date,dayofmonth(current_date)-1)
年:year(date)
月:month(date)
日:day(date)
小时:hour(date)
分:minute(date)
秒:second(date)
第几周:weekofyear(date)
下个月第1天: `add_months(date_sub(current_date,dayofmonth(current_date)-1),1)
hive 常见时间日期函数的使用的更多相关文章
- 银弹谷零代码开发V百科|使用技巧:OMG!这些时间日期函数太好用了吧,盘它
银弹谷零代码开发V百科|使用技巧:OMG!这些时间日期函数太好用了吧,盘它 Hello~everybody!小V又来咯!这次小V给大家带来的是零代码开发V平台常用的时间日期函数.小V知道我们平时常常会 ...
- 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 ...
- 【2017-03-13】Tsql 数学函数、字符串函数、转换函数、时间日期函数
一.数学函数(针对值类型操作) 1.ceiling():取上限 只要小数点后有数字大于0,整数位自动进1 2.floor():取下限 将小数点位舍去,不管小数点位大小 3.round(四舍五入的值,保 ...
随机推荐
- 【Linux】阿里云服务器部署--禅道
Xshell部署环境 回到Xshell界面,连上阿里云服务器,参考上一篇[linux学习1-Xshell连接阿里云ECS服务器](https://www.cnblogs.com/yoyoketang/ ...
- windows系统redmine安装总结
今天在公司服务器上安装了redmine,主要用于项目管理和缺陷跟踪.安装过程比较简单,总结如下: 1.网上下载redmine安装包(bitnami-redmine-3.3.1-0-windows-in ...
- 001-快速搭建Spring web应用【springboot 2.0.4】-gradle、springboot的启动过程分析、gradle多模块构建
一.概述 学习<精通Spring MVC4>书籍笔记 二.笔记 1.快速构建Spring starter web项目几种方式 1>使用Spring Tool Suite生成Start ...
- nginx 部署web页面问题
nginx 部署web页面的时候,路径都是对的,但是css文件就是不起作用,控制台提示如下,原来是格式的问题,截图如下: css 被转成了application/octet-stream,这个是ngi ...
- [php] 索引数组合并选择两数组相加
header("Content-Type:text/html;charset=utf-8");$arr1= Array ( 0 => Array ( 'pic' => ...
- github pages搭建网站(三)
一.个人站点 访问 https://用户名.github.io 搭建步骤 (1)创建个人站点 ->新建仓库(注:仓库名必须是[用户名.github.io]) (2)在仓库下新建index.htm ...
- php背景图片上生成二维码,二维码上带logo 代码示例 (原)
依赖库文件 phpqrcode.php (下载地址://www.jb51.net/codes/189897.html :或者在官网下载:http://phpqrcode.sourceforge.net ...
- obv15 实例6:如果K线柱过多,ZIG将发生变动,导致明显的OBV15指标被隐藏!
obv
- G 面经 && Leetcode: Longest Repeating Character Replacement
Given a string that consists of only uppercase English letters, you can replace any letter in the st ...
- JavaScript原型继承的实例
// 创建构造函数实例(获取DOM节点) <div id="app">测试字符</div>