How to get Time from DateTime format in SQL?

Jig12 picture Jig12 · Oct 10, 2011 · Viewed 835.2k times · Source

I want to get only Time from DateTime column using SQL query using SQL Server 2005 and 2008 Default output:

AttDate                   
==
2011-02-09 13:09:00    
2011-02-09 14:10:00    

I'd like this output:

AttDate                Time 
==
2011-02-09 13:09:00    13:09
2011-02-09 14:10:00    14:10

Answer

t-clausen.dk picture t-clausen.dk · Oct 10, 2011

SQL Server 2008:

SELECT cast(AttDate as time) [time]
FROM yourtable

Earlier versions:

SELECT convert(char(5), AttDate, 108) [time]
FROM yourtable