3

如果我有两个这样的日期时间:

transtime_in, transtime_out

如何以下列格式获取这些日期时间之间的差异:

hh:mm

我用

DATEDIFF(hour, transtime_in, transtime_out) 

但我只知道时间。

4

3 回答 3

7

试试这个——

询问:

DECLARE 
      @transtime_in DATETIME
    , @transtime_out DATETIME

SELECT 
      @transtime_in = '2013-05-19 08:58:07.000'
    , @transtime_out = '2013-05-19 16:40:53.000'

SELECT LEFT(CONVERT(VARCHAR(10), @transtime_out - @transtime_in, 108), 5)

输出:

-----
07:42
于 2013-05-20T08:54:43.137 回答
1
declare @D1 datetime
declare @D2 datetime

set @D1 = '2014-03-25 00:00:00.000'
set @D2 = '2014-03-24 17:14:05.000'

--select datediff(hour, cast(@D1 as time(0)), cast(@D2 as time(0)))
SELECT LEFT(CONVERT(VARCHAR(10), @D2 - @D1, 108), 8)
于 2014-03-27T13:51:56.740 回答
0
declare @D1 datetime
declare @D2 datetime

set @D1 = '2014-03-25 00:00:00.000'
set @D2 = '2014-03-24 17:14:05.000'

SELECT LEFT(CONVERT(VARCHAR(10), @D1 - @D2, 108), 8)
于 2019-02-14T07:55:28.533 回答