SQL Server转换ISO 8601无法正常工作 [英] SQL Server Convert ISO 8601 not working as documented
问题描述
根据 MSDN 转换应该使用127作为样式参数,正确地解析ISO 8601日期,时区。
Per MSDN convert should properly parse ISO 8601 dates with timezone using 127 as the style parameter.
可选的时区指示符Z ,用于使具有时区信息的XML日期时间值映射到没有时区的SQL Server datetime值更容易。 Z是时区UTC-0的指示。其他时区用+或 - 方向的HH:MM偏移量表示。例如:2006-12-12T23:45:12-08:00。
The optional time zone indicator, Z, is used to make it easier to map XML datetime values that have time zone information to SQL Server datetime values that have no time zone. Z is the indicator for time zone UTC-0. Other time zones are indicated with HH:MM offset in the + or - direction. For example: 2006-12-12T23:45:12-08:00.
以下所有内容均为有效的ISO 8601日期,转换日期和/或时间从字符串转换失败
All of the following are valid ISO 8601 dates but return Conversion failed when converting date and/or time from character string.
select convert(datetime, N'2014-02-07T13:51:00+07:00', 127)
select convert(datetime, N'2014-02-07T13:51:00+07', 127)
select convert(datetime, N'2006-12-12T23:45:12-08:00', 127)
<对于这个问题,任何人都有解决方案或解决方法?
Anyone have a solution or workaround for this issue?
推荐答案
解决方法:使用 datetimeoffset
:
Workaround?: Use datetimeoffset
:
select convert(datetimeoffset, N'2014-02-07T13:51:00+07:00', 127) --<-- This one works...
select convert(datetimeoffset, N'2014-02-07T13:51:00+07', 127)
select convert(datetimeoffset, N'2006-12-12T23:45:12-08:00') --<-- and this one works...
这篇关于SQL Server转换ISO 8601无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!