Click here to Skip to main content
16,018,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have lot of data in different different date sql table. i have date is in date time format like 2016-04-31 00:00:00.000 and i want convert this date on nvarchar format like 31-04-2016.I am using sql 2005 and 2008.

thank
with regards
Praveen

What I have tried:

i have lot of data in sql table. i have date is in date time format like 2016-04-31 00:00:00.000 and i want convert this date on nvarchar format like 31-04-2016.I am using sql 2005 and 2008.

thank
with regards
Praveen
Posted
Updated 4-Aug-16 3:12am
Comments
Richard MacCutchan 4-Aug-16 5:51am    
That is the wrong way to do it. You should always store date values as Date or DateTime types. The only time you need to format them is when you wish to display them on screen or report.

MSDN documentation states that you can use:
CAST and CONVERT (Transact-SQL)[^]
or
FORMAT (Transact-SQL)[^]

Note: this is not recommended, unless you want to convert it only for display purposes!
 
Share this answer
 
Comments
Richard Deeming 4-Aug-16 11:47am    
FORMAT was introduced in SQL 2012. It probably won't work in SQL 2005! :)
Maciej Los 4-Aug-16 11:51am    
You're right. I missed that.
You can found your solution here visit it.
SQL Server CONVERT() Function[^]
 
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