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?
Given below are the two methods that we can use to remove milliseconds and seconds from datetime. METHOD 1 : In this method, we will use Convert function to convert date time to varchar and then remove the seconds and milliseconds from it and then convert it back to datetime.
8 bytes. Accuracy. Rounded to increments of .000, .003, or .007 seconds. Default value. 1900-01-01 00:00:00.
smalldatetime descriptionhh is two digits, ranging from 00 to 23, that represent the hour. mm is two digits, ranging from 00 to 59, that represent the minute. ss is two digits, ranging from 00 to 59, that represent the second. Values that are 29.998 seconds or less are rounded down to the nearest minute.
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'
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