今天
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss')

UNIX时间戳转日期函数: from_unixtime

语法: from_unixtime(bigint unixtime[, string format])

返回值: string

说明: 转化UNIX时间戳(从1970-01-01 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式

举例:

hive> select from_unixtime(1323308943,’yyyyMMdd’) from dual;

20111208

获取当前UNIX时间戳函数: unix_timestamp

语法: unix_timestamp()

返回值: bigint

说明: 获得当前时区的UNIX时间戳

举例:

hive> select unix_timestamp() from dual;

1323309615

日期转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

日期时间转日期函数: to_date

语法: to_date(string timestamp)

返回值: string

说明: 返回日期时间字段中的日期部分。

举例:

hive> select to_date(’2011-12-08 10:03:01′) from dual;

2011-12-08

日期转年函数: year

语法: 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

日期转月函数: month

语法: 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

日期转天函数: day

语法: 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

日期转小时函数: hour

语法: hour (string date)

返回值: int

说明: 返回日期中的小时。

举例:

hive> select hour(’2011-12-08 10:03:01′) from dual;

10

日期转分钟函数: minute

语法: minute (string date)

返回值: int

说明: 返回日期中的分钟。

举例:

hive> select minute(’2011-12-08 10:03:01′) from dual;

3

日期转秒函数: second

语法: second (string date)

返回值: int

说明: 返回日期中的秒。

举例:

hive> select second(’2011-12-08 10:03:01′) from dual;

1

日期转周函数: weekofyear

语法: weekofyear (string date)

返回值: int

说明: 返回日期在当前的周数。

举例:

hive> select weekofyear(’2011-12-08 10:03:01′) from dual;

49

日期比较函数: datediff

语法: datediff(string enddate, string startdate)

返回值: int

说明: 返回结束日期减去开始日期的天数。

举例:

hive> select datediff(’2012-12-08′,’2012-05-09′) from dual;

213

日期增加函数: date_add

语法: date_add(string startdate, int days)

返回值: string

说明: 返回开始日期startdate增加days天后的日期。

举例:

hive> select date_add(’2012-12-08′,10) from dual;

2012-12-18

日期减少函数: date_sub

语法: 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日期函数-原生函数(二)

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

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

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

  3. Hive日期函数总结(转学习使用)

    一.时间戳函数 1.获取当前时区的UNIX时间戳:select unix_timestamp(); 2.将指定时间转为UNIX时间戳: select unix_timestamp('2012-03-0 ...

  4. hive日期函数-Demo(二)

    需求:某资产近一个月的资产值 比如:今天是2018年2月28日,近一个月若是按照自然月来算,那么是2018年2月1日至2018年2月28日.最终需要的日期格式为:yyyyMMdd. 当日时间戳 uni ...

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

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

  6. presto和hive日期函数对比

    时间格式转换 日期格式→Unix时间戳 转10位Unix时间戳 数据:2020-07-23 15:01:13 Presto:select to_unixtime(cast('2020-07-23 15 ...

  7. hive日期函数-广发实战(三)

    近一月客户新增常规里程数与额度比即上个月 第一天(包含)到上个月最后一天(包含) 字段是batch_date==>格式是 yyyymmdd ),'MM'),'-',''); +--------- ...

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

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

  9. Hive中日期函数总结

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

随机推荐

  1. STL模板之_map,stack(计算矩阵相乘的次数)

    #include <map>#include <stack>#include <iostream>using namespace std; struct Node ...

  2. 读取配置文件 PropertyPlaceholderConfigurer 的配置与使用

    public class SpringPropertyConfigurer extends PropertyPlaceholderConfigurer { private static Map< ...

  3. 1、Android Bitmap详细介绍

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...

  4. 在mahout安装目录下输入mahout 提示 ERROR: Could not find mahout-examples-*.job

    错误:ERROR: Could not find mahout-examples-*.job in /home/grid/mahout-distribution-0.8 or /home/grid/m ...

  5. MVC 3.0 上传多张图片到服务器

    View关键代码: @using (Html.BeginForm("Create", "Activity", FormMethod.Post, new { en ...

  6. Android-->Genymotion虚拟机(模拟器)的配置

    --> Genymotion 是一套完整的工具,它提供了Android虚拟环境.它简直就是开发者.测试人员.推销者甚至是游戏玩家的福音. 我只能说非常好用,模拟器中顶级,具体好处可以度娘. -- ...

  7. 在IOS输入框中 键盘上显示“搜索”

    移动端web页面上使用软键盘时如何让其显示“前往”(GO)而不是换行?‘ 用一个 form 表单包裹住就会显示前往,单独的一个 input 就会提示换行.下面是测试地址: 有表单:https://js ...

  8. RF 测试代码体会

    这里的需求是完成一个cc2540 RF测试程序.实现功能为开发板按键控制 RF 发射频率的改变. 首先被告知要用PTM来做这个测试程序,然后我去了PTM的介绍文档,地址为 http://process ...

  9. mysql特殊处理

    mysql> create table ef (bc time);Query OK, 0 rows affected (0.03 sec) mysql> insert into ef va ...

  10. Flume+Kafka+Strom基于伪分布式环境的结合使用

    目录: 一.Flume.Kafka.Storm是什么,如何安装? 二.Flume.Kafka.Storm如何结合使用? 1) 原理是什么? 2) Flume和Kafka的整合  3) Kafka和St ...