Per MSDN convert should properly parse ISO 8601 dates with timezone using 127 as the style parameter.
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.
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?
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With