Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server : datetime comparison ignoring few milliseconds [duplicate]

I noticed that 2 datetimes are considered equal if one is

2010-12-31 15:13:48.000 

and the other

2010-12-31 15:13:48.001.

I thought in the beginning that it was rounding up or down to nearest full seconds but it turned out

2010-12-31 15:13:48.002 

registers the difference correctly.

Any idea why this happens?

like image 799
El General Magnifico Avatar asked Oct 23 '25 16:10

El General Magnifico


1 Answers

The datetime data type is accurate to 3 milliseconds (0.0033 seconds), so your results make sense. Values are rounded to 0.000, 0.003, and 0.007. So, your first example is rounded to: "2010-12-31 15:13:48.000" and the second to "2010-12-31 15:13:48.003".

You can read about this in the documentation.

like image 94
Gordon Linoff Avatar answered Oct 25 '25 04:10

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!