Get datetime time using T-SQL?

How to get time for a given datetime value?

I have a datetime in the database:

 2010-09-06 17:07:28.170 

and want only the temporary part:

 17:07:28.170 

Is there a function for this or something else?

+51
datetime sql-server tsql sql-server-2000
Sep 07 '10 at 7:14
source share
5 answers

To add this from SQL Server 2008, there is a TIME data type, so from now on you can:

 SELECT CONVERT(TIME, GETDATE()) 

May be useful for those using SQL 2008+ and find this question.

+74
Sep 07 '10 at 7:23
source share

In the case of SQL Server, this should work.

 SELECT CONVERT(VARCHAR(8),GETDATE(),108) AS HourMinuteSecond 
+17
Sep 07 '10 at 7:18
source share

Assuming the title of your question is correct and you want time:

 SELECT CONVERT(char,GETDATE(),14) 

Edited to include milliseconds.

+10
Sep 07 '10 at 7:18
source share

try it

 SELECT CAST(DataField AS time(7)) AS 'time' 

http://msdn.microsoft.com/en-us/library/bb677243.aspx

+9
Apr 12 2018-12-12T00:
source share
 CAST(CONVERT(CHAR(8),GETUTCDATE(),114) AS DATETIME) 

In SQL Server 2008 +

 CAST(GETUTCDATE() AS TIME) 
+4
Sep 07 '10 at 7:32
source share



All Articles