Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Returning DATEDIFF Value As hh:mm:ss
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00635803
Message ID:
00635824
Vues:
24
>>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!
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform