Showing posts with label datetime. Show all posts
Showing posts with label datetime. Show all posts

Wednesday, November 21, 2012

Examine The Datetime Values

Accuracy of Datetime in SQL Server is 0.00333 millisecond. The millisecond part of value will be converted to a closer times of 0.00333, which is also rounded up to the precision of 1/1000.

0.00333 * 2 = 0.00666
0.00333 * 3 = 0.00999

DECLARE @testDT DATETIME
SET@testDT ='2012-11-11 00:01:00.003'
--this returns  '2012-11-11 00:01:00.003'
SELECT @testDT
SET  @testDT ='2012-11-11 00:01:00.004'
--This returns  '2012-11-11 00:01:00.003'. Because 0.004 is closer to 0.00333 than 0.00666
SELECT @testDT
SET  @testDT ='2012-11-11 00:01:00.005'
-- --This returns  '2012-11-11 00:01:00.007'. Because 0.005 is closer to 0.00666 than 0.00333
--0.00666-0.005=0.00166; 0.005-0.00333= 0.00167
SELECT @testDT
SET  @testDT ='2012-11-11 00:01:00.006'
--SET  @testDT ='2012-11-11 00:01:00.007' 
--SET  @testDT ='2012-11-11 00:01:00.008'  
--above values will all be converted to 0.007 because they are closer to 0.00666 than 0.00999
SELECT @testDT
SET  @testDT ='2012-11-11 00:01:00.009' 
--This returns  '2012-11-11 00:01:00.010'
SELECT @testDT