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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Strange CONVERT UTC/local strings to datetime
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

8 Posts

Posted - 10/10/2012 :  00:47:00  Show Profile  Reply with Quote
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) T2


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.

Flowing Fount of Yak Knowledge

United Kingdom
2179 Posts

Posted - 10/10/2012 :  01:46:59  Show Profile  Visit jackv's Homepage  Reply with Quote
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
Go to Top of Page

Starting Member

8 Posts

Posted - 10/10/2012 :  02:14:26  Show Profile  Reply with Quote
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.

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000