添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Please start any new threads on our new site at https://forums.sqlteam.com . We've got lots of great SQL Server experts to answer whatever question you can come up with.

Why doesn't this query return two different datetime values:
select CONVERT(datetime, '2012-10-29T23:00:00Z', 127) T1, CONVERT(datetime, '2012-10-29 23:00:00', 121) T2produces:T1                      T2----------------------- -----------------------2012-10-29 23:00:00.000 2012-10-29 23:00:00.000
My timezone is UTC+13 so T2 is fine but T1 should have been 2012-11-30 12:00:00.000.BTW: This is on SQLServer 2008 EE (10.50.3720).Any hints as to what I'm doing wrong are greatly appreciated.Pete
SQL Server Books Online has a note "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"Jack Vamvas--------------------http://www.sqlserver-dba.com Thanks Jack.Incidentally, this does not even work:
select CONVERT(datetime, '2006-12-12T23:45:12-08:00', 127)
even though the documentation seems to suggest otherwise, so the only format accepted by datetime style 127 seems to be yyyy-mm-ddThh:mi:ss.mmmZ (the .mmm part being optional).I guess the only real solution is to rewrite the query like this:
SELECT DATEADD(MINUTE, DATEDIFF(MINUTE, GETUTCDATE(), GETDATE()), CONVERT(datetime, '2012-10-29T23:00:00Z', 127)) T1, CONVERT(datetime, '2012-10-29 23:00:00', 121) T2
but I would have thought that the SQL Server would do that implicitly when I do an ISO8601 with time zone Z conversion from a varchar to datetime.Pete