--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)

-- 获取下一个月
add_months(current_date,1)

Hive中日期函数总结的更多相关文章

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

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

  2. MySQL中日期函数的使用

    1. MySQL中日期函数的使用 1.1. 转DATETIME类型为Date类型 将add_time ::56转化为date类型 select * from product where Date(ad ...

  3. hive中标准偏差函数stddev()详细讲解

    1.标准偏差概念 标准偏差(Std Dev,Standard Deviation) -统计学名词.一种度量数据分布的分散程度之标准,用以衡量数据值偏离算术平均值的程度.标准偏差越小,这些值偏离平均值就 ...

  4. Hive中自定义函数

    Hive的自定义的函数的步骤: 1°.自定义UDF extends org.apache.hadoop.hive.ql.exec.UDF 2°.需要实现evaluate函数,evaluate函数支持重 ...

  5. Hive中日期处理

    1.日期函数UNIX时间戳转日期函数:from_unixtime() 函数 格式 返回值 说明 from_unixtime from_unixtime(bigint unixtime[, string ...

  6. Hive的日期函数

    1.unix时间戳转时间函数 语法: from_unixtime(bigint unixtime[, string format]) 返回值: string 说明: 转化UNIX时间戳(从1970-0 ...

  7. 【hive 日期函数】Hive常用日期函数整理

    1.to_date:日期时间转日期函数 select to_date('2015-04-02 13:34:12');输出:2015-04-02122.from_unixtime:转化unix时间戳到当 ...

  8. sql数据库中日期函数---2017-04-12

    一.SQLServer时间日期函数详解 1.  当前系统日期.时间 select getdate() 2. dateadd      在向指定日期加上一段时间的基础上,返回新的 datetime 值 ...

  9. hive中function函数查询

    1. desc function [函数名] desc function xpath; 查询用法: 2. desc function extended [函数名] desc function exte ...

随机推荐

  1. 取Session数据语句在应放在哪里

    UsersModel loginUser = (UsersModel)Session["usersModel"]; 直接放在 public partial class PagesF ...

  2. SQL中使用UPDATE更新数据时一定要记得WHERE子句

    我们在使用 SQL 中的 UPDATE 更新数据时,一般都不会更新表中的左右数据,所以我们更新的数据的 SQL 语句中会带有 WHERE 子句,如果没有WHERE子句,就回更新表中所有的数据,在 my ...

  3. 使用pipeline管道执行redis命令

    pipeline管道可以减少后端与redis的连接次数,从而实现了优化. 原理如下: 使用方法: 未使用pipeline前: strict_redis = get_redis_connection(' ...

  4. Django REST Framework的序列化器是什么?

    # 转载请留言联系 用Django开发RESTful风格的API存在着很多重复的步骤.详细可见:https://www.cnblogs.com/chichung/p/9933861.html 过程往往 ...

  5. selenium TestNG 依赖和忽略测试

    依赖:通过使用Test 注释的dependsOnMethods={"verifyLogin"}子句,verifyAccountInfo 测试指定了它依赖verifyLogin()方 ...

  6. hdu 1140(三维)

    War on Weather Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. springBoot Feign Hystrix Dashboard

    1.引入依赖 <!-- 引入关于 hystrix Dashboard的依赖 --> <dependency> <groupId>org.springframewor ...

  8. 【cocos2d-js官方文档】七、CCFileUtils

    Web引擎 CCFileUtils.js在Web引擎中已经被删除了,原因是FileUtils在原生平台中的文件检索功能在Web端是无法实现的. 二进制文件获取的方法被转移到了cc.loader.loa ...

  9. 阿里云ECS(Centos7.2 64bit)安装Docker

    购买了阿里云的ECS服务器后,一直在尝试安装Docker,使用过Ubuntu和CentOS系统,也一直在查找文档,但都是Docker安装完成后却无法访问,一直在ECS上不停的更换系统盘 再次按官方文档 ...

  10. python 执行顺序

    从上往下顺序执行,定义的方法和类要写在调用之前, 如果有 if __name__ == '__main__'   改方法所在的文件作为启动文件时会被调用,如果作为模块被调用时不会被执行.