如何计算日期差并以天为单位获得输出?

7xzttuei  于 2021-06-27  发布在  Hive
关注(0)|答案(2)|浏览(521)

我试图计算连接到apachedrill的dbeaver中两个日期之间的差异。
前任:

date 1  1/27/2019
date 2  2/01/2019

输出1以天为单位输出2以周为单位

idv4meu8

idv4meu81#

如果日期是字符串格式-

select datediff(
(from_unixtime(unix_timestamp(enddate, dateformat), dateformat)) -
(from_unixtime(unix_timestamp(startdate, dateformat), dateformat)));

前- hive> select datediff(from_unixtime(unix_timestamp('2019-01-28', 'yyyy-MM-dd'), 'yyyy-MM-dd'), from_unixtime(unix_timestamp('2019-01-27', 'yyyy-MM-dd'), 'yyyy-MM-dd'));

g52tjvyc

g52tjvyc2#

你试过了吗 datediff() ?

select datediff(date1, date2) as days_between
       floor(datediff(date1, date2) / 7) as weeks_between

相关问题