ALTER FUNCTION [dbo].[Udf_Get_Posting_Time_To_Up] ( @postingdate datetime ) RETURNS VARCHAR(MAX) AS BEGIN declare @start datetime, @end datetime, @duration varchar(36), @hours varchar(30), @minutes varchar(2), @seconds varchar(30),@days varchar(30) set @start =getdate() set @end = @postingdate set @seconds = abs(datediff(second, @start, @end)) SET @days=@seconds/(3600*24) set @hours = (@seconds-(@days*3600*24))/3600 set @minutes = (@seconds - (@hours * 3600)-(@days*3600*24)) / 60 set @seconds = (@seconds - (@hours * 3600) - (@minutes * 60)-(@days*3600*24)) if cast(@hours as int) < 10 set @hours = '0' + @hours if cast(@minutes as int) < 10 set @minutes = '0' + @minutes if cast(@seconds as int) < 10 set @seconds = '0' + @seconds set @duration =@days +' Days '+@hours + ' Hrs ' + @minutes + ' Min ' + @seconds+' Sec ' RETURN @duration END