Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am using this query to display datetime and i only want to use this but problem is that it gives times in 24 hours format like 16:30, 17:55 but i want to use 12 hours format like $;30, 05:55
SQL
SELECT [ID],REPLACE(convert(varchar, ReceivedMessages.ReceivedDateTime, 113), ' ','/') as RecievingDate FROM [CmsSMSDb].[dbo].[ReceivedMessages]
Posted
Updated 9-Jun-14 2:27am
v2

The 113 tells the convert to use a 24 hour format.
If you use 109, you will get a 12 hour format with AM/PM.

See this link for further details:

http://msdn.microsoft.com/en-us/library/ms187928.aspx[^]
 
Share this answer
 
SQL
SELECT REPLACE(SUBSTRING(convert(varchar, getdate(), 113),0,12),' ','/')+
        SUBSTRING(RIGHT(CONVERT(VARCHAR(26), GETDATE(), 109),14),0,6) AS TEST1

SELECT REPLACE(SUBSTRING(convert(varchar, getdate(), 113),0,12),' ','/')+
        RIGHT(CONVERT(VARCHAR(26), GETDATE(), 109),14) AS TEST2




--Just replace getdate in above query with
ReceivedMessages.ReceivedDateTime

--TEST1 will give output without AM/PM whereas TEST2 will append AM/PM to the date
 
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