Format Time in Sql Server

Posted On // Leave a Comment
There is new Time data type available from SqlServer 2008 which makes it easy to manipulate time. Like

CONVERT(TIME,GETDATE()) AS HourMinute  gives result as 17:23
To format time in SQL Server 2005 and before you can use
CAST(
        LEFT(exampletime, LEN(exampletime)-2) + ':'
        + RIGHT(exampletime, 2) AS VARCHAR(5)
    )  

0 comments:

Post a Comment