Click here to Skip to main content
15,940,246 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
CSS
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
Posted
Updated 19-Sep-22 19:38pm

in Sqlserver2008:

Select cast(your Column as time) [time]
from yourtable
 
Share this answer
 
SQL
SELECT (getdate()),substring(CONVERT(VARCHAR, GETDATE(), 108),0,6) AS Time
 
Share this answer
 
v3
Comments
Naz_Firdouse 9-Apr-13 0:54am    
what's wrong in my answer? why downvote?
use this
SQL
Select AttDate,RIGHT(CONVERT(VARCHAR, AttDate, 100),7) as Time From Tablename
 
Share this answer
 
Try this:
SQL
SELECT CONVERT(VARCHAR(5),GETDATE(),108) AS Time
--From your table
--Assume AttDate is DateTime column of Table1
SELECT AttDate, CONVERT(VARCHAR(5), AttDate,108) AS Time FROM Table1

OR
SQL
SELECT LTRIM(RIGHT(CONVERT(VARCHAR(20), GETDATE(), 100), 7)) AS Time
SELECT AttDate, LTRIM(RIGHT(CONVERT(VARCHAR(20), AttDate, 100), 7)) AS Time FROM Table1


--Amit
 
Share this answer
 
v3
SQL
SELECT CONVERT(VARCHAR, GETDATE(), 108) AS Time

In format hh:mm:ss
 
Share this answer
 
v2
select AttDate,convert(time,AttDate)Time from TableName
 
Share this answer
 
Convert(varchar,getdate(),114)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900