SQL 时间相减,精确到小时

2025-01-26 14:41:19
推荐回答(5个)
回答1:

select cast(datediff(d,'时间1',‘时间2’) as varchar)+'.'+cast(datediff(hour,'时间1',‘时间2’)-datediff(d,'时间1',‘时间2’)*24 as varchar)

回答2:

select datediff('h','2007-1-1 8:30','2007-1-3 9:30');
但是返回49(小时),而不是2.1

回答3:

可以通过datediff函数进行时间差:
sql
:select
datediff(hh,'2012-12-11
8:00:00','2012-12-11
09:31:47')
from
dual
;
语法:
DATEDIFF
(
datepart
,
startdate
,
enddate
)
datepart
缩写
year
yy,
yyyy
quarter
qq,
q
month
mm,
m
dayofyear
dy,
y
day
dd,
d
week
wk,
ww
hour
hh
minute
mi,
n
second
ss,
s
millisecond
ms
microsecond
mcs
nanosecond
ns

回答4:

可以通过datediff函数进行时间差:
sql :select datediff(hh,'2012-12-11 8:00:00','2012-12-11 09:31:47') from dual ;
语法:
DATEDIFF ( datepart , startdate , enddate )
datepart 缩写
year yy, yyyy
quarter qq, q
month mm, m
dayofyear dy, y
day dd, d
week wk, ww
hour hh
minute mi, n
second ss, s
millisecond ms
microsecond mcs
nanosecond ns

回答5:

那2天11小时呢,2.11?