Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a problem, i want to use Time part from my Date Time SQL Column.

Kindly anyone please hep me!

Thanks .
Posted
Comments
Pong D. Panda 12-Jul-11 8:40am    
You're spamming. Go back to your first post and update it, then provide a descriptive info on how do you want to attain this, or what part will it be implemented (backend, SQL, etc)

EASILY found on google. You could put this code into a Sql function if you want to:

SQL
CONVERT(char(10), MyDateTime, 101) AS [Date],
     CONVERT(varchar(2),
          CASE
               WHEN DATEPART([hour], MyDateTime) > 12 THEN CONVERT(varchar(2), (DATEPART([hour], MyDateTime) - 12))
               WHEN DATEPART([hour], MyDateTime) = 0 THEN '12'
               ELSE CONVERT(varchar(2), DATEPART([hour], MyDateTime))
          END
     ) + ':' +
     CONVERT(char(2), SUBSTRING(CONVERT(char(5), MyDateTime, 108), 4, 2)) + ' ' + 
     CONVERT(varchar(2),
          CASE
               WHEN DATEPART([hour], MyDateTime) > 12 THEN 'PM'
               ELSE 'AM'
          END
     ) 
 
Share this answer
 
Comments
[no name] 18-Jul-11 6:39am    
Excellent. My 5 .
You can use
SELECT CONVERT(VARCHAR(10),DATE_FIELD,108)
 
Share this answer
 
SQL
SELECT     CONVERT(nvarchar(50), 'COLUMNNAME', 114) AS Time
FROM         'TABLENAME'
 
Share this answer
 
 
Share this answer
 
Comments
Ger Hayden 12-Jul-11 14:32pm    
OK, so what is wrong with this. The OP put the question up twice, and having answered it felt that a link to the original answer was in order rather than cut and paste.

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