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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Issue while converting datetimeoffset to datetime

Author  Topic 

Sahithikalluri
Starting Member

1 Post

Posted - 2012-11-17 : 00:42:31
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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-11-17 : 05:15:58
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 http://beyondrelational.com/modules/2/blogs/70/posts/10897/understanding-datetime-column-part-i.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -