如何区分两列之间的两个时间段?

时间:2015-05-25 06:56:16

标签: sql sql-server tsql sql-server-2012

我想知道如何区分两列之间的时间段,如时间和时间?

2 个答案:

答案 0 :(得分:0)

DATEDIFF

DATEDIFF (datepart , startdate , enddate)

你问题中datepart dayday。您可以使用dddDECLARE @inTime DATETIME, @outTime DATETIME SET @inTime = '2015-05-01 12:10:09' SET @outTime = '2015-05-22 05:15:36' SELECT DATEDIFF(DAY, @inTime, @outTime) AS timedifferentiate

中的任何一个

<强>示例

SELECT  ,inTime
        ,outTime
        DATEDIFF(DAY, inTime, outTime) AS timedifferentiate
FROM yourTable

在查询中

type="button"

答案 1 :(得分:0)

只需使用减号运算符,然后转换为time

SELECT 
    CONVERT(time, -- Note the time datatype range is 00:00:00.0000000 through 23:59:59.9999999
        CONVERT(datetime, '2015-04-01 19:03') -- Out time
        - CONVERT(datetime, '2015-04-01 09:02') -- In time
    ) TimeDiff