Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning DATEDIFF Value As hh:mm:ss
Message
From
21/03/2002 20:15:21
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00635803
Message ID:
00635824
Views:
23
>>DATEDIFF(hh,dtStart,dtEnd) returns a value in whole integer hours only.
>>
>>How do I return the value expressed as hh:mm:ss ?
>>
>>Thanks for your help.
>>
>
>Try
CONVERT(char(8), DATEADD(second, DATEDIFF(second, dtStart, dtEnd), '20020101'), 8)
Sergey,

Yes. That works well up to 23:59:59 as in the following.
declare @dtStart datetime
declare @dtEnd datetime
set @dtstart = '01/01/2002 9:00:00'
set @dtEnd = '01/02/2002 8:49:00'
SELECT CONVERT(char(8), DATEADD(second, DATEDIFF(second, @dtStart, @dtEnd), '20020101'), 8)  
I really didn't ask it right. I had in mind something that would calculate for any number of hours.

Something that would present partial hours as decimals would be useful for my task also. For example, where 25 hours and 15 minutes = 25.25 hours.

I'm glad that you're thinking well. Thank you! Thank you!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform