This is my basic "test"
select DATEADD(ms,-2,DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0))
, DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)
,case when DATEADD(ms,-2,DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)) != DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0) then 'No Match' else 'Match' end
union all
select DATEADD(ms,-1,DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0))
,DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)
,case when DATEADD(ms,-1,DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)) != DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0) then 'No Match' else 'Match' end
I am trying to understand why MS -2 , subtracts 3 and MS -1 subtracts none.
MSSQL's datetime
data type has a finest granularity of .00333333s (repeating), or roughly 3 milliseconds. Changes less than that will result in either no change, or rounded to 3.
From https://msdn.microsoft.com/en-us/library/cc280460.aspx
datetime2(3) has a precision of one millisecond, and datetime has a precision of 1/300 of a second.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With