hive计算时间差

 

参考:https://blog.csdn.net/sinat_40431164/article/details/80813978

1、首先String to Date格式

yyyy-MM-dd to_date(from_unixtime(UNIX_TIMESTAMP(dt,’yyyy-MM-dd’))) yyyy-MM-dd

 

2、再次使用函数

datediff(to_date(from_unixtime(UNIX_TIMESTAMP( TIME01,'yyyy-MM-dd'))),to_date(from_unixtime(UNIX_TIMESTAMP(TIME02,'yyyy-MM-dd'))))

3、创建视图:

create view hive_external_view as
select substring(TIME01,1,7) days ,
TIME01,
TIME02,
datediff(to_date(from_unixtime(UNIX_TIMESTAMP(TIME01,'yyyy-MM-dd'))),to_date(from_unixtime(UNIX_TIMESTAMP(TIME02,'yyyy-MM-dd'))))
as inhosp_sumdays
from hive_external

 

你可能感兴趣的:(Hive)