这是我的查询
import codecs
f = codecs.open('unicode.rst', encoding='utf-8')
for line in f:
print repr(line)
我得到select DATEDIFF(minute, '2015-06-10 14:00:00.000', '2015-06-10 16:50:00.000') / 60.0
,但我想要2.833333
答案 0 :(得分:2)
这可以为您提供所要求的内容,但请注意,通常2.50等于2.5,表示5/2;你正在使用一种非常罕见的符号
DECLARE @f float
DECLARE @t nvarchar(15)
SELECT @f = DATEDIFF(hour, '2015-06-10 14:00:00.000', '2015-06-10 16:50:00.000')
SELECT @t = CONVERT(nvarchar(10), @f) + N'.' + CONVERT(nvarchar(10), (DATEDIFF(minute, '2015-06-10 14:00:00.000', '2015-06-10 16:50:00.000') - @f*60))
SELECT @t
答案 1 :(得分:1)
所以你想要显示小时和分钟?你可以用这个:
DECLARE @t1 datetime
SET @t1 = '2015-06-10 14:00:00.000'
DECLARE @t2 datetime
SET @t2 = '2015-06-10 16:50:00.000'
SELECT HHmm = CONVERT(varchar(3), DATEDIFF(minute, @t1, @t2) / 60)
+ '.'
+ RIGHT('0' + CONVERT(varchar(2), DATEDIFF(minute, @t1, @t2) % 60), 2)
答案 2 :(得分:1)
DateDiff
函数返回一个整数。将它显示为你需要使用一些数学和铸造的时间:
DECLARE @FromDate datetime = '2015-06-10 14:00:00.000',
@ToDate datetime = '2015-06-10 16:50:00.000'
select CAST(DATEDIFF(minute, @FromDate, @ToDate) / 60 as varchar) + ':' +
CAST(DATEDIFF(minute, @FromDate, @ToDate) % 60 as varchar)