How to convert nvarchar column to datetime type in MS SQL SERVER 2008 R2
I have a nvarchar(50) column named "created_time" in MS SQL with the following string format
Thu Mar 03 09:43:25 +0000 2016
How do I convert it into a datetime type or select "created_time" as a datetime column?
Any help would be much appreciated.
Thanks and Regards, Christina
If you ignore the time zone, you can readily use convert():
select convert(datetime, left(stuff(stuff(created_time, 1, 4, ''), 8, 0, right(created_time, 4) + ' '), 20), 100)
Actually, the intention here is to convert the string to the format "MMM DD YYYY HH:MI:SS", which is default format so cast() could also be used.