1.unix时间戳转时间函数

语法: from_unixtime(bigint unixtime[, string format])
返回值: string 说明: 转化UNIX时间戳(从1970-01-01 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式 举例: hive> select from_unixtime(1323308943,‘yyyyMMdd’) from dual; 20111208

2.获取当前时区的unix时间戳

语法: unix_timestamp()
返回值: bigint 说明: 获得当前时区的UNIX时间戳 举例: hive> select unix_timestamp() from dual; 1323309615

3.时间转unix时间戳

日期转UNIX时间戳函数: unix_timestamp语法:   unix_timestamp(string date)

返回值:   bigint

说明: 转换格式为“yyyy-MM-dd HH:mm:ss“的日期到UNIX时间戳。假设转化失败。则返回0。

举例:

hive>   select unix_timestamp(’2011-12-07 13:01:03′) from dual;

1323234063
指定格式日期转UNIX时间戳函数: unix_timestamp语法:   unix_timestamp(string date, string pattern)

返回值:   bigint

说明: 转换pattern格式的日期到UNIX时间戳。假设转化失败。则返回0。

举例:

hive>   select unix_timestamp(’20111207 13:01:03′,’yyyyMMdd HH:mm:ss’) from dual;

1323234063

4.日期时间转日期函数

语法: to_date(string timestamp)
返回值: string 说明: 返回日期时间字段中的日期部分。 举例: hive> select to_date(’2011-12-08 10:03:01′) from dual; 2011-12-08

5.获取年份的函数

语法: year(string date)
返回值: int 说明: 返回日期中的年。 举例: hive> select year(’2011-12-08 10:03:01′) from dual; 2011 hive> select year(’2012-12-08′) from dual; 2012

6.获取月份的函数

语法: month (string date)
返回值: int 说明: 返回日期中的月份。 举例: hive> select month(’2011-12-08 10:03:01′) from dual; 12 hive> select month(’2011-08-08′) from dual; 8

7.获取天的函数

语法: day (string date)
返回值: int 说明: 返回日期中的天。 举例: hive> select day(’2011-12-08 10:03:01′) from dual; 8 hive> select day(’2011-12-24′) from dual; 24

8.获取小时的函数

语法: hour (string date)
返回值: int 说明: 返回日期中的小时。 举例: hive> select hour(’2011-12-08 10:03:01′) from dual; 10

9.获取分数的函数

语法: minute (string date)
返回值: int 说明: 返回日期中的分钟。 举例: hive> select minute(’2011-12-08 10:03:01′) from dual; 3

10.获取秒的函数

语法: second (string date)
返回值: int 说明: 返回日期中的秒。 举例: hive> select second(’2011-12-08 10:03:01′) from dual; 1

11.获取日期在当前的周数

语法: weekofyear (string date)
返回值: int 说明: 返回日期在当前的周数。 举例: hive> select weekofyear(’2011-12-08 10:03:01′) from dual; 49

12.日期比較函数

语法: datediff(string enddate, string startdate)
返回值: int 说明: 返回结束日期减去開始日期的天数。 举例: hive> select datediff(’2012-12-08′,’2012-05-09′) from dual; 213

13.日期添加函数

语法: date_add(string startdate, int days)
返回值: string 说明: 返回開始日期startdate添加days天后的日期。 举例: hive> select date_add(’2012-12-08′,10) from dual; 2012-12-18

14.日期降低函数

语法: date_sub (string startdate, int days)
返回值: string 说明: 返回開始日期startdate降低days天后的日期。 举例: hive> select date_sub(’2012-12-08′,10) from dual; 2012-11-28

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

  1. Hive中日期函数总结

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

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

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

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

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

  4. hive常用日期函数-模板

    已知日期 要求日期 语句 结果 本周任意一天 本周一 select date_sub(next_day('2016-11-29','MO'),7) ; 2016-11-28 本周任意一天 上周一 se ...

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

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

  6. hive日期函数

    今天select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss') UNIX时间戳转日期函数: from_unixtime 语法: from_ ...

  7. hive函数总结-日期函数

    获取当前UNIX时间戳函数: unix_timestamp语法: unix_timestamp() 返回值: bigint说明: 获得当前时区的UNIX时间戳举例: hive> select u ...

  8. hive日期函数-原生函数(二)

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

  9. hive日期函数-杂谈(一)

    来到广发返现由于历史遗留问题很多时间格式十分杂乱 我将总结一下时间日期的事情 1.hive原生时间函数的功能 2.一些基本业务时间范围的指标的sql案例 3.自定义udf函数让后来人更方便

随机推荐

  1. 记一些stl的用法(持续更新)

    有些stl不常用真的会忘qwq,不如在这里记下来,以后常来看看 C++中substr函数的用法 #include<string> #include<iostream> usin ...

  2. python获取序列中最大值

    test =[ [1, 2, 3], [4, 5, 6], [7, 8, 9]]   #这个就可以看做是二维数组了,直接创建print(test)print(test[:][1])           ...

  3. Loadrunner--Analysis网页细分图

    续LR实战之Discuz开源论坛项目,之前一直是创建虚拟用户脚本(Virtual User Generator)和场景(Controller),现在,终于到了LoadRunner性能测试结果分析(An ...

  4. 使用 JS 关闭警告框及监听自定义事件(amaze ui)

    使用 JS 关闭警告框及监听自定义事件(amaze ui) 一.总结 1.jquery匿名函数:第8行,jquery匿名函数,$(function(){});,有没有很简单,只是少了jquery的前面 ...

  5. 详解javascript: void(0);

    原文 简书原文:https://www.jianshu.com/p/08ae8cbeb3be 什么是javascript: void(0); 我们经常会使用到 javascript:void(0) 这 ...

  6. HDU 2077 汉诺塔IV 递归 通项公式

    刚刚做的HDU 2064很好找规律, 回忆一下: b[1] = 2; b[n] = b[n-1] *3 + 2; 可得b[n]= 3^n-1 不懂的传送门http://blog.csdn.net/mu ...

  7. HDU 2147kiki's game

    KIKI和zz一起玩跳棋游戏,KIKI先.跳棋棋盘有n行m列.在顶行的最右侧位置放上一枚硬币.每次每个人可以把硬币移动到左边,下边或是左下边的空格中.最后不能移动硬币的那个人将输掉比赛. P点:即必败 ...

  8. 巴什博奕小结 HDU2188 HDU1846 HDU2149

    摘自百度百科: 巴什博奕(Bash Game):只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个.最后取光者得胜. 显然,如果n=m+1,那么由于一次最多只能取m个,所以, ...

  9. Visual Studio中你所不知道的智能感知

    在Visual Studio中的智能感知,相信大家都用过.summary,param,returns这几个相信很多人都用过的吧.那么field,value等等这些呢. 首先在Visual Studio ...

  10. java导出word直接下载

    导出word工具类 package util; import java.io.IOException; import java.io.Writer; import java.util.Map; imp ...