I have query like this:
我有这样的疑问:
select t.Paydate,t.DelDate,DATEDIFF(MI, t.Paydate,t.DelDate) as Datdiffernce
from Transaction_tbl t
where t.transactID=19
I am getting out put like this:
我是这样出去的:
Paydate DelDate Datdiffernce
----------------------- ----------------------- ------------
2013-05-07 18:36:50.000 2013-05-07 18:58:32.000 22
Datedifference
am getting only 22 mints.
日期不同,我只能得到22枚金币。
Instead of getting that how I can get date difference in this format hh:mm:ss
?
我怎么才能得到这种格式的日期差异呢?
3 个解决方案
#1
5
Try this,
试试这个,
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
#2
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'
Reference: See here
参考:在这里看到
#3
0
I answered This in a similar question, it may give you something like 07:07:07 instead of 7:7:7
我在一个类似的问题中回答了这个问题,它可能会给出类似于07:07而不是7:7的答案
#1
5
Try this,
试试这个,
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
#2
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'
Reference: See here
参考:在这里看到
#3
0
I answered This in a similar question, it may give you something like 07:07:07 instead of 7:7:7
我在一个类似的问题中回答了这个问题,它可能会给出类似于07:07而不是7:7的答案