假设我有一个StartDate和一个EndDate,我如何格式化或将差异转换为hh:mm:ss? 谢谢。
答案 0 :(得分:1)
试试这个
SELECT CONVERT(Varchar(10), Dateadd(Second, DATEDIFF(Second,StartDate,EndDate),0), 108)
例如:
DECLARE @StartDate DateTime
DECLARE @EndDate DateTime
SET @StartDate = '2014-06-08 07:18:12.893'
SET @EndDate = '2014-06-09 05:58:40.893'
SELECT CONVERT(Varchar(10), Dateadd(Second, DATEDIFF(Second,@StartDate,@EndDate),0), 108)
<强>输出:强>
+---------+
| Time |
+---------+
|22:40:28 |
+---------+
<强> Fiddle Demo 强>