hive时间差

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hive时间差相关的知识,希望对你有一定的参考价值。

参考技术A 说明:

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)是相差的天

链接:https://www.jianshu.com/p/d01d095edc4a

hive将时间转换成星期几

参考技术A 目前没有这样的udf,你可能需要自己用java写个dayofweek函数,下面的连接是目前hive所支持的日期函数

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-DateFunctions本回答被提问者采纳

以上是关于hive时间差的主要内容,如果未能解决你的问题,请参考以下文章

hive求一个字段中最大的时间

在 hive 中将时间戳转换为 hive 格式时出错

大数据之Hive:Hive 计算两个时间相差的分钟

Hive 时间操作

大数据之hive:hive时间函数总结

hive映射Elasticsearch时间date类型问题