Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey guys i need your help.

How do i convert date in this format mm/dd/yyyy to yyyy-mm-dd in sql server

Thanks for your help
Updated 2-Apr-20 2:05am
Richard MacCutchan 7-Nov-13 11:48am    
Don't store dates as strings in your database. Use proper DateTime types to store as absolute values.[^]

This explains the different numbers you can use to create various formats; however, you may want to rethink doing date formatting in SQL. I would recommend doing the formatting in whatever program you are doing.
Share this answer
Select CAST('2013-10-08' as date)
Share this answer
Select Format(Convert(date,ColumnName),'yyyy-mm-dd') from Table_Name
Share this answer
Richard Deeming 2-Apr-20 8:42am    
The Format function was introduced in SQL Server 2016, which was released almost three years after this question was posted.

And as already mentioned, this is a UI concern, not a database concern. Formatting should not be done in the database.
Simply you should convert your format into date data-type using the CONVERT(). Following is an example of the same.

Select convert(date,getdate())
Share this answer
Richard Deeming 2-Apr-20 8:43am    
This is essentially the same as solution 2, which was posted back in 2013.
ishan_shah 3-Apr-20 1:27am    
Yes but just a little difference in the function used by both of us. He/She has used CAST() and I am using CONVERT().

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