Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to get 12 hours date format in sql server-2005

11:59:00
hh:mm:ss

I searched over internet I could not get it
Posted
Updated 8-Mar-17 23:32pm

Try
select convert(varchar, myDate, 108)
 
Share this answer
 
Comments
sacraj 1-Jul-11 7:09am    
I would like to get date in 12 hours format
not in 24 hours format the above query gives 24 hours
Abhinav S 1-Jul-11 7:17am    
You can then try select convert(varchar, myDate, 109).

But this will add AM/PM to the result.
Select LEFT(RIGHT(Convert(DateTime, yourcoulumn, 0),14),8) + RIGHT(Convert(DateTime, yourcoulumn, 0),2) from yourtable
 
Share this answer
 
v3
Comments
sacraj 1-Jul-11 7:09am    
I would like to get date in 12 hours format
not in 24 hours format the above query gives 24 hours
Prerak Patel 1-Jul-11 7:14am    
Try this now. I've updated answer.
sacraj 1-Jul-11 7:31am    
When I run this query Select RIGHT(Convert(DateTime, getdate(), 0),7)

I get 5:01PM but I need time like this 05:01:00 PM
Prerak Patel 1-Jul-11 7:35am    
Updated again.
You can use different styles.
http://msdn.microsoft.com/en-us/library/ms187928.aspx
SQL
Select RIGHT(Convert(VARCHAR(20), ColumnName,100),7) as ampm

from TableName
 
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