hive日期函数
今天
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日期函数的更多相关文章
- hive日期函数-原生函数(二)
1. from_unixtime 日期函数UNIX时间戳转日期函数: from_unixtime 语法:from_unixtime(bigint unixtime[, stringformat]) 返 ...
- 【hive 日期函数】Hive常用日期函数整理
1.to_date:日期时间转日期函数 select to_date('2015-04-02 13:34:12');输出:2015-04-02122.from_unixtime:转化unix时间戳到当 ...
- Hive日期函数总结(转学习使用)
一.时间戳函数 1.获取当前时区的UNIX时间戳:select unix_timestamp(); 2.将指定时间转为UNIX时间戳: select unix_timestamp('2012-03-0 ...
- hive日期函数-Demo(二)
需求:某资产近一个月的资产值 比如:今天是2018年2月28日,近一个月若是按照自然月来算,那么是2018年2月1日至2018年2月28日.最终需要的日期格式为:yyyyMMdd. 当日时间戳 uni ...
- hive日期函数-杂谈(一)
来到广发返现由于历史遗留问题很多时间格式十分杂乱 我将总结一下时间日期的事情 1.hive原生时间函数的功能 2.一些基本业务时间范围的指标的sql案例 3.自定义udf函数让后来人更方便
- presto和hive日期函数对比
时间格式转换 日期格式→Unix时间戳 转10位Unix时间戳 数据:2020-07-23 15:01:13 Presto:select to_unixtime(cast('2020-07-23 15 ...
- hive日期函数-广发实战(三)
近一月客户新增常规里程数与额度比即上个月 第一天(包含)到上个月最后一天(包含) 字段是batch_date==>格式是 yyyymmdd ),'MM'),'-',''); +--------- ...
- hive函数总结-日期函数
获取当前UNIX时间戳函数: unix_timestamp语法: unix_timestamp() 返回值: bigint说明: 获得当前时区的UNIX时间戳举例: hive> select u ...
- Hive中日期函数总结
--Hive中日期函数总结: --1.时间戳函数 --日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数 select unix_timestamp(); --获得当前时区 ...
随机推荐
- iOS7程序内部如何打开评分页面
测试发现项目在iOS7下 无法打开评价页面,但是iOS6是正常: 查了一下发现应该是iOS7 改变链接了,有个网友给出了以下的解决办法 把旧的链接改成 appString =[NSStringstri ...
- Android Studio下SQLite数据库的配置与使用(完)
一,AS开发app用,所用的数据库有限制,必须使用较小的SQLite(MySql和Sql Server想想就不显示) 但是该数据库并不需要我们单独下载,安装的SDK中已经有了,在C:\AndroidS ...
- 视频转gif
如何把视频变成GIF https://shop16541393.koudaitong.com/v2/feature/1x6q09fa?openid=ov0dfwb6-DBFqTzvekSNAjT59U ...
- 客户端HTTP断点续传的原理
其实断点续传的原理很简单,就是在Http的请求上和一般的下载有所不同而已. 打个比方,浏览器请求服务器上的一个文时,所发出的请求如下:假设服务器域名为wwww.scu.edu.cn,文件名为down. ...
- 腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿
腾讯优测是专业的android自动化测试平台,拥有上千款真机,彻底解决android碎片化问题! 这里我要说的不是闪光灯的硬件特征,也不是说底层驱动的原理,我只是跟大家聊一聊在项目中遇到的一些关于闪光 ...
- 设置Android studio内容的主题
下载主题Jar包 http://color-themes.com/?view=theme&id=563a1a6e80b4acf11273ae76 导入主题: File->Import s ...
- c数据结构栈的基本操作(字符逆序输出)
线性栈 输入字符,再输出 #include "stdafx.h" #include<stdlib.h> #include<malloc.h> #define ...
- C# 各种数据类型的最大值和最小值常数
using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO ...
- Ant——ant的使用
---------------------------------------------------------------------------------------------------- ...
- Android项目的目录结构
assets 资产目录, 存放一个文件的 这个文件会被打包到应用程序的apk(安装包 ) bin 编译后的文件目录 gen 自动生成文件的目录 roject.properties 代表编译的版本 ...