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时间日期函数及典型场景应用的更多相关文章

  1. Hive中日期函数总结

    --Hive中日期函数总结: --1.时间戳函数 --日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数 select unix_timestamp(); --获得当前时区 ...

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

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

  3. SQL-数学、字符串、时间日期函数和类型转换

    --数学函数 --ABS绝对值,select ABS(-99)--ceiling取上限,select CEILING(4.5)--floor去下限select FLOOR(4.5)--power 几次 ...

  4. SQLite中的时间日期函数(转)

    SQLite包含了如下时间/日期函数: datetime().......................产生日期和时间date()...........................产生日期tim ...

  5. PostgreSQL的时间/日期函数使用

    PostgreSQL的常用时间函数使用整理如下: 一.获取系统时间函数 1.1 获取当前完整时间 select now(); david=# select now(); now ----------- ...

  6. SQL servcer 时间日期函数、数据类型转换

    1.时间日期函数 2.数据类型转换 3.习题 建立两个表,一个部门表,一个人员表.部门:部门的编号,部门的名称,部门的职责.人员:人员的编号,姓名,年龄,性别,cid所属部门

  7. [转] PostgreSQL的时间/日期函数使用

    PS:http://blog.csdn.net/love_rongrong/article/details/6712883 字符串模糊比较 日期类型的模糊查询是不能直接进行的,要先转换成字符串然后再查 ...

  8. SQL server 数据库——数学函数、字符串函数、转换函数、时间日期函数

    数学函数.字符串函数.转换函数.时间日期函数 1.数学函数 ceiling()--取上限  select ceiling(oil) as 油耗上限 from car floor()--取下限 sele ...

  9. SQLite中的时间日期函数

    SQLite包含了如下时间/日期函数: datetime().......................产生日期和时间 date()...........................产生日期 t ...

随机推荐

  1. 简单SQL注入

    既然是简单的,估计也就是''字符型把,输入'or'1 以下是输出结果,or没被过滤,单引号也没有 呢么用union联合注入试试,提交了'-1 union/**/select 1 and '1,发现回显 ...

  2. PHP content-type为"application/json"的post过来的数据$_POST接受不到的问题

    ajax默认是以application/x-www-form-urlencoded方式提交.也就是常见的表单提交方式.在PHP中使用$_POST方式可以轻松获取. 但如果将ajax的请求头强制指定为a ...

  3. Python爬虫基础之认识爬虫

    一.前言 爬虫Spider什么的,老早就听别人说过,感觉挺高大上的东西,爬网页,爬链接~~~dos黑屏的数据刷刷刷不断地往上冒,看着就爽,漂亮的校花照片,音乐网站的歌曲,笑话.段子应有尽有,全部都过来 ...

  4. 【原创】运维基础之Docker(4)实用工具ctop

    ctop类似于top,top监控的是进程,ctop监控的是容器(container top) 安装 # wget https://github.com/bcicen/ctop/releases/dow ...

  5. 【linux】统计文件夹中文件行数

    统计当前目录下,排除venv目录,剩余所有py文件的行数 wc -l `find -path ./venv -prune -o -name '*py'`

  6. DOS批处理高级教程(还不错)(转)

    前言 目录 第二节 常用特殊符号     1.@  命令行回显屏蔽符     2.%  批处理变量引导符     3.>   输出重定向符     4.>>  输出重定向符     ...

  7. python 的bif

    函数在类里面就叫做方法from sys import pi 导入sys模块里面的pi方法import sys as system 命名为新的名字dir(sys) 查看sys模块里面都提供了哪些东西he ...

  8. js分析 天_眼_查 字体文件

    0. 参考 js分析 猫_眼_电_影 字体文件 @font-face 1. 分析 1.1 定位目标元素 1.2 查看网页源代码 1.3 requests 请求提取得到大量错误信息 对比猫_眼_电_影抓 ...

  9. Cesium 动态更换模型贴图方法

    参考资料 github 讨论地址 示例代码地址 示例代码 var viewer = new Cesium.Viewer('cesiumContainer'); var scene = viewer.s ...

  10. Spring Data JPA入门

    1. Spring Data JPA是什么 它是Spring基于ORM框架.JPA规范封装的一套JPA应用框架,可使开发者用极简的代码即可实现对数据的访问和操作.它提供了包括增删改查等在内的常用功能, ...