Click here to Skip to main content
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 2:14am
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 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 4

SELECT CONVERT(VARCHAR, GETDATE(), 108) AS Time
In format hh:mm:ss
  Permalink  
v2
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?

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Afzaal Ahmad Zeeshan 82
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2014
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