i have a column (nvarchar),there are datetimes in there but as a string.I want to change that column’s type into smalldatetime but before i want to format all string dates into a same datetime format.But i cant succeed it.Some of them are like this “2007-07-10”,some of them are reverse of this “02.07.2008”. How can i change them into one format for example dd.mm.yyyy.
(ms sql server 2008)
i have a column (nvarchar),there are datetimes in there but as a string.I want
Share
If you only have those 2 formats, this is how you can do it.
I am assuming
‘02.07.2008’ has format ‘dd.mm.yyyy’
‘2007-07-10’ has format ‘yyyy-mm-dd’
If you have more formats than that, you have to alter the ‘case’ in the ‘select’ clause accordingly
Output
The format is standard for a date field, but if you want to store it as a varchar, you can format it as dd.mm.yyyy like this instead.
Output
I have to point out that you should always store a date as a date and not a varchar in the database when possible.