Why does conversion from DATETIME to DATETIME2 appear to change value?

Based on this MSDN blog post, DATETIME precision is .00333 seconds, while DATETIME2 (or DATETIME2(7) explicitly) has 100 ns precision. So even comparing DATETIME to DATETIME2(3), which would seem to have the same precision, DATETIME2(3) is more precise.

This weird 3.33 ms precision of DATETIME is the reason why when comparing seemingly equal values, you can get a difference.


A breaking change was introduced in SQL Server 2016 with regards to conversion and comparison of datetime and datetime2. The changes are detailed in this knowledge base article.

In summary, values were rounded during the conversion in SQL 2014 and earlier versions whereas the full precision is considered nowadays. This improves performance but introduces issues when converting and comparing these unlike types.


To me, when you do comparison, you actually should convert data with high precision to low precision to avoid such "difference"

DECLARE @DateTime DATETIME='2018-01-18 16:12:25.113'
DECLARE @DateTime2 DATETIME2='2018-01-18 16:12:25.1130000'
SELECT @DateTime, cast(@DateTime2 as datetime), DATEDIFF(NANOSECOND, @DateTime, cast(@DateTime2 as datetime))

The result is

enter image description here


datetime2 is shorthand for datetime2(7), which indicates you want 7 digits for fractional seconds (the maximum). Try a datetime2(3) if you want something closer to a datetime.

Also, be aware that datetime2(3) is more precise than a datetime. The latter rounds to the nearest 0.000, 0.003, or 0.007 by design.