我在MS SQL中有一个名为“created_time”的nvarchar(50)列,其字符串格式如下
2016年3月3日星期四09:43:25 +0000
如何将其转换为日期时间类型或选择“created_time”作为日期时间列?
任何帮助将非常感激。
感谢致敬, 克里斯蒂娜
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
最满意答案
如果忽略时区,则可以使用convert() :
select convert(datetime, left(stuff(stuff(created_time, 1, 4, ''), 8, 0, right(created_time, 4) + ' '), 20), 100)实际上,这里的意图是将字符串转换为格式“MMM DD YYYY HH:MI:SS”,这是默认格式,因此也可以使用cast() 。
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.
更多推荐
发布评论