Difference between dates: Time Format

,

This function returns the difference between dates in the H:MM:SS format.

create  function timeDiff(@StartDate datetime, @EndDate datetime)

returns varchar(25)

as

begin

declare @diffSecond int,
@cSecond char(2),
@cMinute char(2),
@vcHour  varchar(21),
@vcTime  varchar(25)


select@diffSecond = datediff(ss, @StartDate, @EndDate),
@cSecond =   @diffSecond % 60,
@cMinute =  (@diffSecond /60)   % 60,
@vcHour  =  (@diffSecond /(60*60))% 60,
@vcTime = @vcHour + ':' + 
replicate('0', 2 - len(rtrim(@cMinute))) + rtrim(@cMinute) + ':' +
replicate('0', 2 - len(rtrim(@cSecond))) + rtrim(@cSecond),
@vcTime = isnull(@vcTime, '')

return @vcTime


end

Rate

5 (1)

Share

Share

Rate

5 (1)