Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 363
E-Madd Avatar asked Jul 20 '10 03:07

E-Madd


People also ask

How can remove seconds and milliseconds from datetime in SQL?

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.

What is datetime precision in SQL Server?

8 bytes. Accuracy. Rounded to increments of .000, .003, or .007 seconds. Default value. 1900-01-01 00:00:00.

How do I use Smalldatetime in SQL?

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.


1 Answers

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' 
like image 168
Gabe Avatar answered Oct 11 '22 14:10

Gabe