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. Stm32 GPIO复习

    地点:中图四楼. 1.七个寄存器 配置寄存器:GPIOx_CPL.GPIOx_CPH; 数据寄存器:GPIOx_IDR.GPIOx_ODR: 置位/复位寄存器:GPIOx_BSRR 复位寄存器:GPI ...

  2. IIS命令行静默安装脚本-python

    #coding=utf8 import platform from subprocess import Popen,PIPE,STDOUT import sys,os def run_cmd(cmd, ...

  3. JS基础之传参(值传递、对象传递)

    一.概念 我们需了解什么是按值传递(call by value),什么是按引用传递(call by reference).在计算机科学里,这个部分叫求值策略(Evaluation Strategy). ...

  4. Lua中的闭包

    [什么是闭包?] 闭包在Lua中是一个非常重要的概念,闭包是由函数和与其相关的引用环境组合而成的实体.我们再来看一段代码: function newCounter() return function ...

  5. $Django 路飞之显示视频,Redis存购物车数据,优惠卷生成表,优惠卷的一个领取表。(知识小回顾)

    知识小回顾之json序列化问题 精髓:支持python的几种数据类型(注意不是对象,不能放对象),其次是tuple变list. ensure_ascii:默认值True,如果dict内含有non-AS ...

  6. android SDK模拟器环境搭建

    一.下载安装android SDK 两种方式: (1)官网下载(需FQ):https://developer.android.com/studio/index.html (2)无需FQ下载:http: ...

  7. vue-标签页组件

    content <template> <div class="tab-content"> <TabBar v-model="activeKe ...

  8. Penettation testing with the bush Shell

    1.  Network Reconnaissance first we can use the command to gather the site information by whois eg : ...

  9. Zabbix(一)

    安装一台CentOS: CentOS-7.4-x86_64-DVD-1708 https://www.cnblogs.com/xiewenming/p/7732144.html https://blo ...

  10. elasticsearch-5.2.1在windows下的安装方法

    elasticsearch-5.2.1安装方法 1. 安装java 下载安装java jdk 1.8 以上 配置java环境变量 右击[我的电脑]---[属性]-----[高级系统设置]---[环境变 ...