如何以小时和分钟为单位计算两次约会时间的差异

时间:2021-10-18 19:11:55

If I have two datetimes like this :

如果我有两个这样的数据时间:

transtime_in, transtime_out

How to get the difference between those datetimes in the following format :

如何以下列格式获取这些数据时间的差异:

hh:mm

I use

我使用

DATEDIFF(hour, transtime_in, transtime_out) 

but i get the hours only .

但我只有时间。

2 个解决方案

#1


6  

Try this one -

试试这个,

Query:

查询:

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)

Output:

输出:

-----
07:42

#2


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)

#1


6  

Try this one -

试试这个,

Query:

查询:

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)

Output:

输出:

-----
07:42

#2


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)