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(); --获得当前时区 ...
随机推荐
- 拿到新机器,进行初始化和部署Nginx的过程
1. 在/etc/ansbile/hosts中添加主机init 2. 在sysinit.yml中修改要初始化的机器: hosts: init 3. 设置不检查key export ANS ...
- Hadoop学习资料
转自:http://cloud21.iteye.com/blog/607175 第一手资源 hadoop官方网站 hadoop.apache.org 最权威的官方资源之一 dev.yahoo.hado ...
- mysql 日期类型比较
MySQL 日期类型:日期格式.所占存储空间.日期范围 比较. 日期类型 存储空间 日期格式 日期范围 ------------ ------ ...
- boundingRectWithSize
CGSize labsize1=[label1.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-80, MAXFLOAT) options:NSSt ...
- HDU1016 dfs
刷回溯的时候发现我对DFS思路很不清晰,总是做着做着就乱了,刷个水题找找思路. 题意:经典DFS,找出所有的能让1~n的数形成素数环的序列(相邻相加为素数): #include <iostrea ...
- 一些sql语句的常用总结(重要)
select primary_flag from tc_contact where primary_flag !=0 select dept_id,dept_name,tree_level,tree_ ...
- WINDONWS7+VS2012+Cocos2d-x
一:准备工作 准备下载文件 1.VS2012,到处都有咱就不发链接了. 2.Cocos2d-x的最新版本 http://www.cocos2d-x.org/projects/cocos2d-x/wik ...
- activity 和 生命周期: 消息通信
实际上关于activity大概流程已经了解了,在深入的话方向应该是ams的处理操作和界面创建和view绘制.这些话题之后再谈,activity是一个gui程序,其中离不开的就是消息通讯,也就是在消息循 ...
- oop、try_except、单例模式
本节大纲: 面向对象特性:封装.继承.多态.一:多态:python本身是多态,他的参数可以多种类型.可以是字符串.数字.列表等.当传入参数的时候,python可以判断参数的数据类型.而在java C# ...
- C# 多线程写文件,时常写不成功
在项目中,做一个文本日志功能 为了不影响页面响应速度,所以使用了多线程,在测试的时候,风险文件写入时常不成功,经过一番周折, 发现th.IsBackground = true;后台线程不为主线程的子线 ...