Search code examples
sql-servert-sql

SQL Server remove milliseconds from datetime


select *
from table
where date > '2010-07-20 03:21:52'

which I would expect to not give me any results... EXCEPT I'm getting a record with a datetime of 2010-07-20 03:21:52.577

how can I make the query ignore milliseconds?


Solution

  • You just have to figure out the millisecond part of the date and subtract it out before comparison, like this:

    select * 
    from table 
    where DATEADD(ms, -DATEPART(ms, date), date) > '2010-07-20 03:21:52'