Reputation: 767
Suppose I have a StartDate and an EndDate, how do I format or convert the difference into hh:mm:ss? Thank you.
Upvotes: 1
Views: 269
Reputation: 28403
Try this
SELECT CONVERT(Varchar(10), Dateadd(Second, DATEDIFF(Second,StartDate,EndDate),0), 108)
For Example:
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)
Output:
+---------+
| Time |
+---------+
|22:40:28 |
+---------+
Upvotes: 1