如何在hive中减去2个时间戳列,并将结果存储在其等效小时格式的单独列中?
答案 0 :(得分:2)
假设您有给定格式的时间戳: 2016-10-16 10:51:00.000
您可以尝试以下操作:
SELECT
cast(
round(
cast((e-s) as double) * 1000
) as int
) time_difference
FROM (SELECT cast(starttime as double) s, cast(endtime as double) e from table1) q;
它将为您提供两个时间戳的差异,以毫秒为单位。然后,您可以将其转换为您预期的格式(小时,天等)。
答案 1 :(得分:0)
使用unix_timestamp函数将配置单时间戳转换为自纪元以来的秒数。减去unix时间点结果可以在几秒钟内得出答案。
SELECT start_dttm,
(unix_timestamp(end_dttm) - unix_timestamp(start_dttm))/60 AS duration_in_minutes
FROM dev_edw.audit_history_hb
WHERE script_name LIKE '%0_hive_d%'
AND parent_audit_id is null
ORDER BY start_dttm desc