Search code examples
sqlsql-serverdatetimesmalldatetime

30 second offset with smalldatetime comparison on SQL


I've came across an odd problem while comparing dates (actually smalldatetime) in SQL Server. It seems like there is a 30 seconds offset/bias while comparing dates close to the end of the day:

This is correct:

enter image description here

But this is definitely not correct:

enter image description here

What is happening here? Is math broken?


Solution

  • The smalldatetime type has a accuracy of one minute so the literal '2019-12-31 23:59:30' is rounded to '2020-01-01 00:00:00'.