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. Android学习笔记之ViewFlipper

    <1>被添加到ViewFlipper中的两个或两个以上的视图之间将执行一个简单的ViewAnimator动画.一次仅能显示一个子视图.如果需要,可以设置间隔时间使子视图像幻灯片一样自动显示 ...

  2. ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第一篇:准备工作

    摘要      本文将简要介绍这个文章系列的目的.形式及大体内容.并且完成开始学习这个系列前所必要的准备工作. 前言      ASP.NET MVC作为微软官方的MVC解决方案,推出有一段时间了.可 ...

  3. HorizontalListView中使用notifyDataSetChanged()和notifyDataSetInvalidated()

    今天在项目中用到了水平ListView控件HorizontalListView,也是我在网上找的个开源HorizontalListView直接在项目中使用.我是把HorizontalListView放 ...

  4. 双向链表(自己写的c++类)

    UVA还是上不去T T哭瞎了. 只好老老实实的研究上回买的书了. 写得有点长.好吧,我只是来复习C++类的. 特意用class 而不用struct写链表. 数据结构还没学...双向链表就当先预习了. ...

  5. IOS上架App Store商店步骤

    苹果官方在2015年05-06月开发者中心进行了改版,网上的APP Store上架大部分都不一样了,自己研究总结一下,一个最新的上架教程以备后用. 原文地址:http://www.16css.com/ ...

  6. Python中的Sets数据结构

    Python的set和其他语言类似,是一个无序不重复元素集,基本功能包括关系测试和消除重复元素.集合对象支持union(联合),intersection(交),difference(差)和sysmme ...

  7. 【BZOJ 3238】[Ahoi2013]差异

    [链接]h在这里写链接 [题意]     还有更简洁的题目描述吗/xk [题解]     对于lenti+lentj这一部分,比较好处理.     可以弄一个前缀和.     然后O(N)扫描一遍. ...

  8. Java 学习(19):Java 多线程编程

    Java 多线程编程 Java 给多线程编程提供了内置的支持.一个多线程程序包含两个或多个能并发运行的部分.程序的每一部分都称作一个线程,并且每个线程定义了一个独立的执行路径. 多线程是多任务的一种特 ...

  9. 小小ARC造福无数码农

    今天无意中看到非常久之前的一个项目,古老的语法规范,还有更让人战战兢兢"内存管理代码"! 在这不得不说OC中内存管理的三种分类: Mannul Reference Counting ...

  10. [spark]spark 编程教程

      参考: 英文:https://spark.apache.org/docs/latest/programming-guide.html 中文:http://www.cnblogs.com/lujin ...