如何在MS SQL SERVER 2008 R2中将nvarchar列转换为datetime类型(How to convert nvarchar column to datetime type in

编程入门 行业动态 更新时间:2024-10-27 18:20:44
如何在MS SQL SERVER 2008 R2中将nvarchar列转换为datetime类型(How to convert nvarchar column to datetime type in MS SQL SERVER 2008 R2)

我在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.

更多推荐

本文发布于:2023-07-24 00:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239328.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   中将   类型   如何在   SERVER

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!