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)
 Issue while converting datetimeoffset to datetime
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 11/17/2012 :  00:42:31  Show Profile  Reply with Quote
DECLARE @datetimeoffset datetimeoffset(3)
DECLARE @datetime datetime

SELECT @datetimeoffset = '2012-11-08T17:22:13.575+00:00'
SELECT @datetime = @datetimeoffset
SELECT @datetimeoffset AS '@datetimeoffset ', @datetime AS 'datetime'
Result of above SQL is
@datetimeoffset datetime
2012-11-08 17:22:13.575 +00:00 2012-11-08 17:22:13.577

The result should be '2012-11-08 17:22:13.575', can anyone please let me know why the milliseconds value is incorrect

K Sahithi

Premature Yak Congratulator

22864 Posts

Posted - 11/17/2012 :  05:15:58  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
It is becuase the datetime datatype is rounding the values. Datetime value is rounded to 0.000,0.003 or 0.007 milliseconds. As the last digit is 5 it is rounded to 7. Refer this post and read the section named Rounding


Failing to plan is Planning to fail
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