Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 date difference format

Author  Topic 

dirtyfishtank
Starting Member

8 Posts

Posted - 2012-01-12 : 21:43:30
Hey all,

I have a stored procedure which returns a start date and an end date and duration. Is there away to set the duration to be in 'HH:MM:SS' rather than the defualt of 'YYYY:MM:DD HH:MM:SS' using a function like DATEDIFF


startdate,
enddate,
DATEDIFF (HOUR, startdate, enddate) AS duration

dirtyfishtank
Starting Member

8 Posts

Posted - 2012-01-13 : 02:41:26
I found this works quite well

Convert(CHAR(5), DateAdd(min
, DateDiff(min, start, stop), '00:00:00')
, 108)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-13 : 03:22:07
from 2008 onwards you've time datatype so you can even cast to time datatype to get this if version is 2008 or above

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -