转自大神 http://www.oratea.net/?p=944

无论做什么数据,都离不开日期函数的使用。

这里转载一下Hive的日期函数的使用,写的相当完整。

日期函数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日期转换函数2的更多相关文章

  1. Mysql日期转换函数、时间转换函数

    Mysql日期转换函数.时间转换函数 一.MySQL 获得当前日期时间 函数 1,获得当前日期+时间(date + time)函数:now(): select now(); 结果: :: 2,获得当前 ...

  2. hive中的日期转换函数

    1.unix时间戳转时间函数   语法: from_unixtime(bigintunixtime[, string format]) 返回值: string   说明: 转化UNIX时间戳(从197 ...

  3. JS的数据类型判断函数、数组对象结构处理、日期转换函数,浏览器类型判断函数合集

    工具地址:https://github.com/BothEyes1993/bes-jstools bes-jstools 100多个基础常用JS函数和各种数据转换处理集合大全,此工具包是在 outil ...

  4. Js 日期转换函数(UTC时间转换及日期想加减)

    IOS上Js日期转换中new Date("yyyy-mm-dd")不能正常工作,必须使用new Date("yyyy/MM/dd"); 日期相加减: Date. ...

  5. mysql中的日期转换函数(类似oracle中的to_date)

    最近使用mysql开发一个项目,发现没有像之前在用oracle数据中那样有to_date方法.mysql中实现日期格式化的方法为date_to_str('日期字符串','日期格式'),而且mysql中 ...

  6. MySQL(Unix时间戳、日期)转换函数

    unix_timestamp() mysql> select unix_timestamp(); +------------------+ | unix_timestamp() | +----- ...

  7. C# 日期转换函数

    string.Format("{0:d}",dt);//2005-11-5 string.Format("{0:D}",dt);//2005年11月5日 str ...

  8. sql server 日期转换函数 convert()

    --内容来自:http://hi.baidu.com/muqingz/item/8fb7b3ca8a485b0cac092f7b Select CONVERT(varchar(100), GETDAT ...

  9. Sql server 日期函数和日期转换

    时间函数 SQL Server Date 函数 下面的表格列出了 SQL Server 中最重要的内建日期函数: 函数 描述 GETDATE() 返回当前日期和时间 DATEPART(Type,dat ...

随机推荐

  1. JDK本地内存追踪NMT

    通常情况下, JVM占用的内存不仅仅是-Xmx, -Xms等指定的大小, 因为JVM也是一个应用, 它需要额外的空间去完成它的工作, 除了堆外, JVM会分配内存的地方包括以下这些: Metaspac ...

  2. C++之开灯问题(链表)

    有n盏灯,编号为1~n.第1个人把所有灯打开,第2个人按下所有编号为2的倍数开关(这些灯将被关掉),第3个人按下所有编号为3的倍数的开关,以此类推.一共有k个人,问最后有哪些灯开着?输入n和k,输出开 ...

  3. Gin上传文件到MongoDB gridfs

    目录 上传图片 下载图片 上传图片 func imagePost(c *gin.Context) { image, err := c.FormFile("file") if err ...

  4. [译]开发者须知的SOLID原则

    原文:SOLID Principles every Developer Should Know – Bits and Pieces SOLID Principles every devloper sh ...

  5. 勒索病毒,华为/H3C三层交换机/路由器用ACL访问控制实现端口禁用

    前不久勒索病毒横行,很多人都纷纷中招,从公司到个人,损失相当惨重.有些公司在互联网入口上做了控制,但是这样并非完全,万一有人把中了毒的U盘插入网内设备上呢?那我们的内网中很有可能集体中招(打过相关补丁 ...

  6. Linux RedHat7.0_64位系统中安装Oracle_11g_R2

    步骤一: 当然是安装rhel7操作系统啦(废话),建议在安装过程中系统软件类型选择最后一项[Server with GUI].其他的默认一般即可. 步骤二:在初装完成的系统中无法像Windows那样直 ...

  7. C# 简单的定时器使用

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  8. Hadoop—MapReduce计算气象温度

    Hadoop-MapReduce计算气象温度 1 运行环境说明 1.1 硬软件环境 主机操作系统:Mac OS 64 bit ,8G内存 虚拟软件:Parallers Desktop12 虚拟机操作系 ...

  9. Parameter 0 of method sqlSessionTemplate in org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration required a single bean, but 2 were found:

    Parameter 0 of method orderSqlSessionFactory in com.config.MultipleDBConfig required a single bean, ...

  10. css3 media媒体查询器用法总结(附js兼容方法)

    css3 media媒体查询器用法总结 标签:class   代码   style   html   sp   src 随着响应式设计模型的诞生,Web网站又要发生翻天腹地的改革浪潮,可能有些人会觉得 ...