Hive: How to calculate time difference Hive: How to calculate time difference hadoop hadoop

Hive: How to calculate time difference


Language manual contains description of all available datetime functions. Difference in seconds can be calculated in such way: 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.

It might be better to write a UDF instead of putting all this into your query.


You need to convert the HH:MM:SS times to seconds, get the difference between them and re-arrange it as another HH:MM:SS time.