Hive的日期函数
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的日期函数的更多相关文章
- Hive中日期函数总结
--Hive中日期函数总结: --1.时间戳函数 --日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数 select unix_timestamp(); --获得当前时区 ...
- 【hive 日期函数】Hive常用日期函数整理
1.to_date:日期时间转日期函数 select to_date('2015-04-02 13:34:12');输出:2015-04-02122.from_unixtime:转化unix时间戳到当 ...
- hive时间日期函数及典型场景应用
1.hive取得当前日期时间: 1.1) 取得当前日期: select current_date(); 1.2) 取得当前日期时间: select current_timestamp(); 1.3) ...
- hive常用日期函数-模板
已知日期 要求日期 语句 结果 本周任意一天 本周一 select date_sub(next_day('2016-11-29','MO'),7) ; 2016-11-28 本周任意一天 上周一 se ...
- Hive 时间操作函数(转)
1.日期函数UNIX时间戳转日期函数: from_unixtime 语法: from_unixtime(bigint unixtime[, string format]) 返回值: string ...
- hive日期函数
今天select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss') UNIX时间戳转日期函数: from_unixtime 语法: from_ ...
- hive函数总结-日期函数
获取当前UNIX时间戳函数: unix_timestamp语法: unix_timestamp() 返回值: bigint说明: 获得当前时区的UNIX时间戳举例: hive> select u ...
- hive日期函数-原生函数(二)
1. from_unixtime 日期函数UNIX时间戳转日期函数: from_unixtime 语法:from_unixtime(bigint unixtime[, stringformat]) 返 ...
- hive日期函数-杂谈(一)
来到广发返现由于历史遗留问题很多时间格式十分杂乱 我将总结一下时间日期的事情 1.hive原生时间函数的功能 2.一些基本业务时间范围的指标的sql案例 3.自定义udf函数让后来人更方便
随机推荐
- Mycat快速入门
1.Mycat介绍 Mycat 是一个开源的分布式数据库系统,是一个实现了 MySQL 协议的的Server,前端用户可以把它看作是一个数据库代理,用 MySQL 客户端工具和命令行访问,而其后端可以 ...
- 51Nod——N1118 机器人走方格
https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1118 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 ...
- UIViewController所有API的学习。
<欢迎大家加入iOS开发学习交流群:QQ529560119> /* UIViewController is a generic controller base class tha ...
- 通达OA二次开发 对通达2015版微信查询用户信息模块升级开发(图文)
OA提供对微信的支持这一点做的很好,用户使用起来也更方便了. 而当中的个别功能还有待完好,比现在天要说的这个微信查询用户信息模块. 升级前的用法:输入@+用户中文名.而且要求全然匹配,然而在实际使用中 ...
- App.js和App.css(用于移动应用的js和css)
App.js和App.css(用于移动应用的js和css) 一.App.js和App.css(用于移动应用的js和css) App.js 是一个轻量级的 JavaScript UI 库,用来创建移动的 ...
- iOS_01_什么是ios
* ios是一款由苹果公司开发的操作系统(os是Operating Systen的简称),就像平时在电脑上用的Window XP.Window 7.都是操作系统. * 那什么是操作系统呢?操作系统其实 ...
- decode与case when
语法 decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) select * from reglike; ,),'aaa','yes','no') decode from ...
- [Nuxt] Build a Navigation Component in Vue.js and Use in a Nuxt Layout
You can isolate parts of templates you want to re-use into components, but you can also reuse those ...
- [Nuxt] Navigate with nuxt-link and Customize isClient Behavior in Nuxt and Vue.js
Because Nuxt renders pages on the server, you should use the nuxt-link components to navigate betwee ...
- swift项目第二天:初始化项目
初始化项目 项目的部署版本 之后项目会运行在哪些系统中 横竖屏的支持 iPhone应用一般只支持横屏 iPhone游戏一般支持竖屏 iPad横竖屏都支持 设置项目的图标和启动图片 项目的图标(美工做好 ...