In a table, there is a column BeginDate
of type char(10)
and all the records are saved in 2020/05/06
format.
How can I change the data type to Date
?
Advertisement
Answer
You could strip the /
characters and then you have the ISO format yyyyMMdd
.:
TRY_CONVERT(date,REPLACE(StringDate,'/',''),112)
But the real solution is fix your design; stop storing dates as a varchar
.