我想知道如何区分两列之间的时间段,如时间和时间?
答案 0 :(得分:0)
DATEDIFF (datepart , startdate , enddate)
你问题中datepart
day
是day
。您可以使用d
,dd
和DECLARE @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