Reputation: 7260
I want to convert given date into the format YYYY-MM-DD
.
Given date:
DECLARE @Date1 VARCHAR(50) = '30-01-2015'
Now I want to convert it into the 2015-01-30
.
Try1:
SELECT CONVERT(VARCHAR(50),'30-01-2015',126)
Try2:
SELECT CONVERT(VARCHAR(50),'30-01-2015',120)
For both try the result remain same that is 30-01-2015
.
Upvotes: 6
Views: 83400
Reputation: 157
LEFT(CONVERT(VARCHAR(19), CONVERT(datetime, my_date, 3), 120),10)
if you want to remove the time. Also
CONVERT(VARCHAR(10), CONVERT(datetime, my_date, 3), 120)
Upvotes: 0
Reputation: 2171
Convert date from dd-mm-yyyy hh:mm:ss to yyyy-mm-dd hh:mm:ss in SQL Server
convert(datetime,'18-11-2019 00:00:00',105) // will return 2019-11-18 00:00:00.000
Upvotes: 1
Reputation: 35780
Try this:
DECLARE @Date1 VARCHAR(50) = '30-01-2015'
SELECT CONVERT(VARCHAR(10), CONVERT(date, @Date1, 105), 23)
Upvotes: 19