hive的时间函数
发布日期:2022-02-27 02:37:50
浏览次数:35
分类:技术文章
本文共 2364 字,大约阅读时间需要 7 分钟。
unix_timestamp() 是hive系统时间,格式是timestamp,精确到秒。
unix_timestamp(ymdhms) 是把时间转换成timestamp格式,是2018-05-23 07:15:50格式。 unix_timestamp() - unix_timestamp(ymdhms) 是两个时间转换为timestamp之后相减,timestamp单位是秒,相减之后是两个时间之间相差的秒数。 CAST((unix_timestamp() - unix_timestamp(ymdhms)) % 60 AS int) 是相差的秒数。 CAST((unix_timestamp() - unix_timestamp(ymdhms)) / 60 AS int) % 60 是相差的分钟数。 CAST((unix_timestamp() - unix_timestamp(ymdhms)) / (60 * 60) AS int) % 24 是相差的小时数。 concat(CAST((unix_timestamp() - unix_timestamp(ymdhms)) / (60 * 60 * 24) AS int) 是相差的天数。 常用时间格式转换固定日期转换成时间戳select unix_timestamp('2016-08-16','yyyy-MM-dd') --1471276800select unix_timestamp('20160816','yyyyMMdd') --1471276800select unix_timestamp('2016-08-16T10:02:41Z', "yyyy-MM-dd'T'HH:mm:ss'Z'") --147131296116/Mar/2017:12:25:01 +0800 转成正常格式(yyyy-MM-dd hh:mm:ss)select from_unixtime(to_unix_timestamp('16/Mar/2017:12:25:01 +0800', 'dd/MMM/yyy:HH:mm:ss Z'))时间戳转换程固定日期select from_unixtime(1471276800,'yyyy-MM-dd') --2016-08-16select from_unixtime(1471276800,'yyyyMMdd') --20160816select from_unixtime(1471312961) -- 2016-08-16 10:02:41select from_unixtime( unix_timestamp('20160816','yyyyMMdd'),'yyyy-MM-dd') --2016-08-16select date_format('2016-08-16','yyyyMMdd') --20160816返回日期时间字段中的日期部分select to_date('2016-08-16 10:03:01') --2016-08-16取当前时间select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss')select from_unixtime(unix_timestamp(),'yyyy-MM-dd')返回日期中的年select year('2016-08-16 10:03:01') --2016返回日期中的月select month('2016-08-16 10:03:01') --8返回日期中的日select day('2016-08-16 10:03:01') --16返回日期中的时select hour('2016-08-16 10:03:01') --10返回日期中的分select minute('2016-08-16 10:03:01') --3返回日期中的秒select second('2016-08-16 10:03:01') --1返回日期在当前的周数select weekofyear('2016-08-16 10:03:01') --33返回结束日期减去开始日期的天数select datediff('2016-08-16','2016-08-11')返回开始日期startdate增加days天后的日期select date_add('2016-08-16',10)返回开始日期startdate减少days天后的日期select date_sub('2016-08-16',10)返回当天三种方式SELECT CURRENT_DATE;--2017-06-15SELECT CURRENT_TIMESTAMP;--返回时分秒--2017-06-15 19:54:44SELECT from_unixtime(unix_timestamp());--2017-06-15 19:55:04返回当前时间戳Select current_timestamp--2018-06-18 10:37:53.278返回当月的第一天select trunc('2016-08-16','MM') --2016-08-01返回当年的第一天select trunc('2016-08-16','YEAR') --2016-01-01
————————————————
版权声明:本文为CSDN博主「可乐大牛」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_44173974/article/details/113829168转载地址:https://blog.csdn.net/weixin_43377681/article/details/116542398 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月13日 16时57分41秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
web.py框架
2019-04-27
web.py学习笔记
2019-04-27
python的代码缩进
2019-04-27
A* Pathfinding Project (Unity A*寻路插件) 使用教程
2019-04-27
bash学习笔记
2019-04-27
sqlite学习
2019-04-27
手把手教你实现Unity与Android的交互
2019-04-27
手把手教你使用Unity的Behavior Designer
2019-04-27
Unity3D摄像机裁剪——NGUI篇
2019-04-27
lua深拷贝一个table
2019-04-27
app运行提示Unable to Initialize Unity Engine
2019-04-27
spring boot 与 Ant Design of Vue 实现修改按钮(十七)
2019-04-27
spring boot 与 Ant Design of Vue 实现删除按钮(十八)
2019-04-27
spring boot 与 Ant Design of Vue 实现新增角色(二十)
2019-04-27
spring boot 与 Ant Design of Vue 实现修改角色(二十一)
2019-04-27
spring boot 与 Ant Design of Vue 实现删除角色(补二十一)
2019-04-27
spring boot 与 Ant Design of Vue 实现左侧组织树(二十三)
2019-04-27
spring boot 与 Ant Design of Vue 实现新增组织(二十四)
2019-04-27