Hive中日期函数总结:
1.时间戳函数
日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数
select unix_timestamp(); --获得当前时区的UNIX时间戳
select unix_timestamp('2017-09-15 14:23:00'); 
select unix_timestamp('2017-09-15 14:23:00','yyyy-MM-dd HH:mm:ss');
select unix_timestamp('20170915 14:23:00','yyyyMMdd HH:mm:ss');

--时间戳转日期
select from_unixtime(1505456567); 
select from_unixtime(1505456567,'yyyyMMdd'); 
select from_unixtime(1505456567,'yyyy-MM-dd HH:mm:ss'); 
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'); --获取系统当前时间

2.获取当前日期: current_date
hive> select current_date from dual
2017-09-15

3.日期时间转日期:to_date(string timestamp) 
hive> select to_date('2017-09-15 11:12:00') from dual;
2017-09-15

3.获取日期中的年/月/日/时/分/秒/周
with dtime as(select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss') as dt)
select year(dt),month(dt),day(dt),hour(dt),minute(dt),second(dt),weekofyear(dt)
  from dtime
  
4.计算两个日期之间的天数: datediff
hive> select datediff('2017-09-15','2017-09-01') from dual;  
14

5.日期增加和减少: date_add/date_sub(string startdate,int days)
hive> select date_add('2017-09-15',1) from dual;    
2017-09-16
hive> select date_sub('2017-09-15',1) from dual;    
2017-09-14

其他日期函数
查询当前系统时间(包括毫秒数): current_timestamp;  
查询当月第几天: dayofmonth(current_date);
月末: last_day(current_date)
当月第1天: date_sub(current_date,dayofmonth(current_date)-1)

下个月第1天: add_months(date_sub(current_date,dayofmonth(current_date)-1),1)

hive时间的更多相关文章

  1. Hive 时间操作

    Hive 时间转换 UNIX时间戳概念:因为UNIX时间戳只是一个秒数,一个UNIX时间戳在不同时区看来,时间是不同的.如UNIX时间戳0,在0时区看来是1970-01-01 00:00:00,在东八 ...

  2. Hive时间操作[转]

    时间字段格式化 from_unixtime(unix_timestamp(VisitTime),'yyyy-MM-dd') 日期函数UNIX时间戳转日期函数: from_unixtime语法:   f ...

  3. HIVE 时间操作函数

    转自http://www.oratea.net/?p=944 日期函数UNIX时间戳转日期函数: from_unixtime语法:   from_unixtime(bigint unixtime[,  ...

  4. Hive 时间日期处理总结

    最近用hive比较多,虽然效率低,但是由于都是T+1的业务模式.所以也就不要求太多了,够用就行.其中用的吧比较多就是时间了,由于大数据中很多字段都不是标准的时间类型字段,所以期间涉及了很多的时间日期字 ...

  5. hive时间日期函数及典型场景应用

    1.hive取得当前日期时间: 1.1) 取得当前日期: select current_date(); 1.2) 取得当前日期时间: select current_timestamp(); 1.3) ...

  6. Hive 时间函数总结【转】

    1.日期函数UNIX时间戳转日期函数: from_unixtime语法:from_unixtime(bigint unixtime[, stringformat]) 返回值: string说明: 转化 ...

  7. Hive presto和hive时间格式转换

    1.北京时间格式   to   unix时间格式 数据格式: 2017-11-17 08:28:13 2017-11-17 08:28:10 2017-11-17 08:27:51.343 2017- ...

  8. Hive 时间操作函数(转)

    1.日期函数UNIX时间戳转日期函数: from_unixtime 语法:   from_unixtime(bigint unixtime[, string format]) 返回值: string ...

  9. hive 时间函数

    使用时发现:1.datediff可以传入timestamp类型参数     官网文档: Date Functions The following built-in date functions are ...

随机推荐

  1. oracle的备份方式

    一.完全备份 exp 用户/密码@库名 file=存储位置 二.RMAN https://www.cnblogs.com/Latiny/p/6920428.html RMAN在数据库服务器的帮助下实现 ...

  2. 《深入浅出深度学习:原理剖析与python实践》第八章前馈神经网络(笔记)

    8.1 生物神经元(BN)结构 1.人脑中有100亿-1000亿个神经元,每个神经元大约会和其他1万个神经元相连 2.细胞体:神经元的主体,细胞体=细胞核+细胞质+细胞膜,存在膜电位 3.树突:从细胞 ...

  3. DataBase安装及简单配置

    下载以及安装 打开mysql官网下载页面:http://dev.mysql.com/downloads/mysql/ 用管理员身份打开cmd命令行工具,cd到解压文件的bin目录 输入mysqld i ...

  4. Python数据结构--链表

    class Node(): def __init__(self, dataval=None): self.dataval = dataval self.nextval = None class SLi ...

  5. Shrio Demo

    package com.atguigu.shiro.helloworld; import org.apache.shiro.SecurityUtils; import org.apache.shiro ...

  6. Python接口测试之报告(十五)

    在本文章中,主要使用jenkins和编写的自动化测试代码,来生成漂亮的测试报告,关于什么是CI这些 我就不详细的介绍了,这里我们主要是实战为主. 首先搭建java的环境,这个这里不做介绍.搭建好jav ...

  7. oracle exp direct 执行机制

    使用直接导出模式 direct=y exp 比传统模式导出快一倍 oracle提供2种模式导出表数据,传统模式CONVENTIONAL PATH和直接模式DIRECT PATH,有direct指定. ...

  8. 上传文件表单file,限制上传文件类型的方法--参数accept

    我们使用<input type="file" />来上传文件,但是当你只想要上传某种格式的文件,比如说(jpg)文件时.可以通过accept来限制. <form& ...

  9. intent使用Serializable传递对象

    package com.pingyijinren.test; import android.content.Intent; import android.support.v7.app.AppCompa ...

  10. [bzoj1692][Usaco2007 Dec]队列变换_后缀数组_贪心

    队列变换 bzoj-1692 Usaco-2007 Dec 题目大意:给定一个长度为$n$的字符串.每次从头或尾取出一个字符加到另一个字符串里.要求变换后生成的字符串字典序最小,求字典序最小的字符串. ...