我试图计算连接到apachedrill的dbeaver中两个日期之间的差异。前任:
date 1 1/27/2019 date 2 2/01/2019
输出1以天为单位输出2以周为单位
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'));
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'));
g52tjvyc2#
你试过了吗 datediff() ?
datediff()
select datediff(date1, date2) as days_between floor(datediff(date1, date2) / 7) as weeks_between
2条答案
按热度按时间idv4meu81#
如果日期是字符串格式-
前-
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'));
g52tjvyc2#
你试过了吗
datediff()
?