如果我有两个这样的日期时间:
transtime_in, transtime_out
如何以下列格式区分这些日期时间:
hh:mm
我用
DATEDIFF(hour, transtime_in, transtime_out)
但我只得到了几个小时。
答案 0 :(得分:6)
试试这个 -
<强>查询:强>
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
答案 1 :(得分: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)
答案 2 :(得分: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)