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(); --获得当前时区 ...
随机推荐
- MVC乱码可能的原因
1.数据传输不对,或者根本没有进控制器 2.分部视图建立时一定要选择
- Django url()函数详解
url()函数看起来的格式象: url(r^/account/$', views.index, name=index) ,它可以接收四个参数,分别是两个必选参数: regex . view 和两个可选 ...
- RSA IOS和Java
整了三天 终于可以相互加密解密了,今天我给大家讲讲我遇到的大坑. 这篇文章只是做一个整理,帮大家理清一下步骤的而已 在ios端做证书 来实现我们和java的交流 需要4个文件. 一.首先,打开Term ...
- WAMP环境启动失败处理办法
点击控制面板->系统与安全->管理工具->查看事件日志->windows日志->应用程序 查看错误日志,查找错误并解决
- C#实现右下角弹出窗口效果
/// <summary> /// 窗体动画函数 注意:要引用System.Runtime.InteropServices; /// </summary> /// <pa ...
- 关于项目使用可配置的properties 文件的实现
maven项目在项目install的时候配置如下 注意value的\ 之后利用spring3.0 以后的读取properties 配置如下 然后我们就可以在setter方法 ...
- C++ 中的对象布局
C++中的涉及到虚表时,类对象的布局分为:虚表与数据成员,子类包含派生类布局,假设下面一个程序: #include <iostream> using namespace std; clas ...
- 将Rmarkdown文件转为pdf文件
knitr包只能够将R markdown文件转为html格式,若想要将其转化为pdf格式,还要安装另一个包 # Install and load package install.packages(&q ...
- Toolkit.getImage获取图片
public class Img { private static final Toolkit tk = Toolkit.getDefaultToolkit(); public static fina ...
- hdu3078 伪LCA……
题意:有 n 点的一颗树,每个节点有格子的权值,现在有两种操作,修改一个点的权值,或者求两点之间的路径上的第 k 大的权值. 其实看到这个题,就在 YY 各种做法,询问后得到貌似可能是关于主席树.树链 ...