Time To Text
Posted by Philip Leitch
Thursday, June 11, 2009 6:30:03 PM
create FUNCTION Time_To_Text
(@Time as datetime)
returns Varchar(255)
begin
/*
www.prlsoftware.com
Author: Philip Leitch
Date: 2005
Purpose: Displays just the time component of a datetime/smalldatetime value.
Copyright: Philip Leitch 2005
Licensing: This code may be used or modified but if the code is included in a software package attribution to me must be made.
Liability: The developer assumes all liability when using this code.
Notes:
Currently returns the time in 24 hour time.
*/
DECLARE @RETURN AS VARCHAR(255)
SET @RETURN = right('0' + cast(datepart(HOUR, @Time) as varchar),2) + ':' +
right('0' + cast(datepart(minute, @Time) as varchar),2) + ':' +
right('0' + cast(datepart(SECOND, @Time) as varchar),2) + '.' +
right('00' + cast(datepart(MILLISECOND, @Time) as varchar),3)
return @RETURN
end
go
-- =============================================
-- Example to execute function
-- =============================================
--One of these values will be in 24 hour format.
select dbo.Time_To_Text(getdate()), dbo.Time_To_Text(getdate()+.5)
Copyright 2009 Philip Leitch