hive中的时间戳操作
Timestamp operations in hive
如何减去 hive 中的 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;
它会给你两个时间戳的毫秒差值。然后您可以将其转换为您期望的格式(小时、天等)。
使用unix_timestamp 函数将配置单元时间戳转换为自纪元以来的秒数。减去 unix timestemp 结果以秒为单位给出答案。
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
如何减去 hive 中的 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;
它会给你两个时间戳的毫秒差值。然后您可以将其转换为您期望的格式(小时、天等)。
使用unix_timestamp 函数将配置单元时间戳转换为自纪元以来的秒数。减去 unix timestemp 结果以秒为单位给出答案。
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