Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I guys , i was tried different date formats but doesn't got the required Date Format.

I want the date format as : 01-Mar-2013 05:30:58 PM




Please any one help me.
Posted
Updated 1-Mar-13 1:02am
v3

SQL
SELECT REPLACE(CAST(convert(varchar, getdate(), 113) AS VARCHAR(11)), ' ','-') + ' ' + LTRIM(RIGHT(CONVERT(VARCHAR(30), GETDATE(), 109), 15))
 
Share this answer
 
Comments
gvprabu 1-Mar-13 7:48am    
Your Output is coming Different, pls check
CH Guravaiah 1-Mar-13 7:52am    
thanks for giving information. But here is 01-Mar-2013 6:19:58:380PM . from the date no need the Milliseconds. I want only 01-Mar-2013 05:30:58 PM these format. Please give me the correct Answer.
Hi ,

Check the following Query....

SQL
SELECT GETDATE(), REPLACE(CONVERT(varchar(30), GETDATE(),106),' ','-')+' ' + LTRIM(RIGHT(CONVERT(CHAR(20), GETDATE(), 22), 11))


Regards,
GVPrabu
 
Share this answer
 
v2
Hi,

refer below articles to more on SQL date formats.
SQL Server Date Formats[^]
CAST and CONVERT (Transact-SQL)[^]
SQL SERVER – Display Datetime in Specific Format [^]

pickup which suites best for your requirement.

hope it helps.
 
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