Converting datetime to only timeformat

  • Hello Friends,

    I have a table named Table1 and a column named CreationTime.

    CreationTime has the datatype as datetime.

    It gives the output as mm/dd/yyyy hh:mm:ss

    But I want the output as hh:mm:ss

    I am aware that I can use CAST or CONVERT function, but I am not getting a proper syntax for the same.

    I would appreciate if anyone of you could help me to get the current syntax for what I wish to achieve.

    Thank you,

    notes4we

  • http://msdn.microsoft.com/en-us/library/ms187928(SQL.90).aspx

    108 or 114 seem to do it

    SELECT CONVERT(nvarchar(30), GETDATE(), 108)

    16:10:04

    SELECT CONVERT(nvarchar(30), GETDATE(), 114)

    16:10:04:510

    unless you are using SQL 2008, you can CAST datetime to 'time' type

    SELECT CAST(GETDATE() AS TIME)

    16:10:49.9630000

    SQLServerNewbieMCITP: Database Administrator SQL Server 2005
  • Thank you Jerry. I am using SQL Server 2005 and I uesd this:

    SELECT CONVERT(varchar(8),CreationTime,108)

    FROM Table1

    It is working fine.

    Thank you.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply