Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my datatbase date is stored as
2012-02-18 00:00:00.000 this format.
After using this following SQL
convert(char,datetimefield,103) i am getting 30/08/2012

but i want to get it like this following way
Thrusday,August,30,2012

Can anyone please tell me which sql query helps me to get the above format?
Thanks in advance.
Posted

Hi,
Try this:
SQL
SELECT DATENAME(DW, GETDATE())+', '+ DATENAME(MONTH, GETDATE())+', '+CONVERT(VARCHAR(2), DAY(GETDATE()))+', '+CONVERT(VARCHAR(12),YEAR(GETDATE()))


--Amit
 
Share this answer
 
Comments
sahabiswarup 30-Aug-12 8:44am    
5 from me..
Thanks a lot..
\m/
_Amy 30-Aug-12 8:49am    
Welcome. :)
To do something with this type of format, you are going to need to do something custom. If you were using SQL Server 2012, there is a format command that makes this easy. However, I'm going to assume you aren't using SQL 2012 yet. In that case, your best bet is a UDF that allows you to pass in the format you want and get back the date the way you are expecting. The best example I have seen is from Pinal Dave:

http://blog.sqlauthority.com/2008/08/14/sql-server-get-date-time-in-any-format-udf-user-defined-functions/[^]

That should do any format you want.
 
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