Sql server日期格式转换 [英] Sql server date format conversion

查看:79
本文介绍了Sql server日期格式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的专家,



我希望将此日期'星期四,2013年10月31日10:51:18 + 0000'格式转换为sql中的sql server日期时间格式服务器。请帮助实现这一目标。我的要求是将此字符串日期数据插入sql server datetime字段。

解决方案

请看看这个...



SQL日期时间 [ ^ ]



 对于 SQL Server 使用  CONVERT  

INSERT INTO 表1([ date ])
SELECT CONVERT (< span class =code-keyword> datetime ,' 05/09/2013' 103





谢谢!


ħ我是Sunil,



如果时区部分对您很重要,这里有一个解决方案:

 < span class =code-keyword>选择 转换 datetime  convert (datetimeoffset,stuff(substring('  Thu,2013年10月31日10: 51:18 +0000' 5  27 ), 26  0 ' :'), 1 ), 1 ); 



您可以更改时区部分以查看不同的输出。



如果所有时区都 +0000 所以你可以完全忽略它:

 选择 cast(substring(' < span class =code-string> 2013年10月31日星期四10:51:18 +0000' 5  22  as   datetime 





使用 SUBSTRING 是为SQL Server选择可理解的部分。



祝你好运。


Dear Experts,

I want to convert this date 'Thu, 31 Oct 2013 10:51:18 +0000' format to sql server datetime format in sql server. Please help on this to achieve the goal. My requirement is to insert this string date data to a sql server datetime field.

解决方案

Please take a look at this...

SQL Date Time[^]

For SQL Server use CONVERT

INSERT INTO Table1 ([date])
SELECT CONVERT(datetime, '05/09/2013', 103)



Thanks!


Hi Sunil,

If the timezone part is important to you, here is one solution :

select convert(datetime, convert(datetimeoffset, stuff(substring('Thu, 31 Oct 2013 10:51:18 +0000',5,27),26,0,':'),1),1);


You can change the timezone part to see different outputs.

If all of the time zones are +0000 so you can ignore it completely:

select cast( substring('Thu, 31 Oct 2013 10:51:18 +0000',5,22) as datetime)



Using the SUBSTRING is to choose the understandable part for the SQL Server.

Good Luck.


这篇关于Sql server日期格式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆