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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.