Hive:如何计算时差 [英] Hive: How to calculate time difference
问题描述
我的要求很简单,就是如何计算配置单元中两列之间的时间差 示例 p> Time_Start: 10:15:00 Time_End : 11:45:00 我需要做的(Time_End-Time_Start)= 1:30:00 请注意,这两列都在String数据类型中,有助于获得所需的结果.. 语言手册包含所有可用日期时间函数的说明。以秒为单位的差值可以这样计算: 编写UDF 可能会更好而不是将所有这些放到您的查询中。 My requirement is simple how to calculate the time difference between two column in hive Example Time_Start: 10:15:00 Time_End: 11:45:00 I need to do (Time_End-Time_Start) =1:30:00 Note both the columns are in String datatype kindly help to get required result.. Language manual contains description of all available datetime functions. Difference in seconds can be calculated in such way: It might be better to write a UDF instead of putting all this into your query. 这篇关于Hive:如何计算时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
hour(time_end)* 3600 + minute(time_end)* 60 + second(time_end) - hour(time_start)* 3600 - minute(time_start)* 60 - second (TIME_START)
。您可以用 from_unixtime(...,'HH:mm:ss')
来包装它以获得格式化的时差。
hour(time_end) * 3600 + minute(time_end) * 60 + second(time_end) - hour(time_start) * 3600 - minute(time_start) * 60 - second(time_start)
. You can wrap it with from_unixtime(..., 'HH:mm:ss')
to get formatted time diff.