我有这样的查询:
select t.Paydate,t.DelDate,DATEDIFF(MI, t.Paydate,t.DelDate) as Datdiffernce
from Transaction_tbl t
where t.transactID=19
我这样出去了:
Paydate DelDate Datdiffernce
----------------------- ----------------------- ------------
2013-05-07 18:36:50.000 2013-05-07 18:58:32.000 22
Datedifference
我只得到22分钟。
而不是按照这种格式hh:mm:ss
答案 0 :(得分:5)
试试这个,
SELECT convert(varchar(10),DATEDIFF(hour,t.Paydate,t.DelDate))+'hr:'
+convert(varchar(10),DATEDIFF(minute,t.Paydate,t.DelDate)% 60) + 'mnts:'
+convert(varchar(10),DATEDIFF(SECOND,t.Paydate,t.DelDate)% 60) +'seconds'
AS 'DIFF IN HH:MM:SS'
FROM Transaction_tbl t
WHERE t.transactID=19
答案 1 :(得分:0)
Declare @starttime datetime, @endtime datetime, @seconds int
Set @starttime ='2013-10-01 15:05:17'
Set @endtime = '2013-10-01 15:10:16'
set @seconds = DateDiff(second, @starttime, @endtime)
Select Convert(varchar(10), @seconds/3600) + 'hr:'
+Convert(varchar(10), (@seconds % 3600)/60) + 'mnts:'
+Convert(varchar(10), (@seconds % 3600) % 60) + 'seconds'
参考:See here
答案 2 :(得分:0)
我在一个类似的问题中回答This,它可能会给你一些像07:07:07而不是7:7:7