Click here to Skip to main content
11,642,855 members (73,471 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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 8-Apr-13 1:14am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

in Sqlserver2008:

Select cast(your Column as time) [time]
from yourtable
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

use this
Select AttDate,RIGHT(CONVERT(VARCHAR, AttDate, 100),7) as Time From Tablename
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try this:
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
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
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

SELECT (getdate()),substring(CONVERT(VARCHAR, GETDATE(), 108),0,6) AS Time
  Permalink  
v3
Comments
Naz_Firdouse at 9-Apr-13 0:54am
   
what's wrong in my answer? why downvote?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

SELECT CONVERT(VARCHAR, GETDATE(), 108) AS Time
In format hh:mm:ss
  Permalink  
v2

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

  Print Answers RSS
0 DamithSL 258
1 Sergey Alexandrovich Kryukov 230
2 jyo.net 180
3 OriginalGriff 170
4 Afzaal Ahmad Zeeshan 155
0 Mika Wendelius 485
1 DamithSL 457
2 OriginalGriff 365
3 Afzaal Ahmad Zeeshan 258
4 Sergey Alexandrovich Kryukov 254


Advertise | Privacy | Mobile
Web03 | 2.8.150731.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100