Ok, I need something like this:
datediff(second, date_one, date_two) < 1
dates are stored in a column 'datetime' type
UPDATE
I want开发者_JAVA技巧 to find dates which differ in less than several (say, 10) seconds
Second is the smallest unit in DATETIME fields. If you want to check that the difference is less than 1 second, that means that the two dates must be the same, in which case you can simply use the equivalency operator.
To check the time difference using bigger units you can use TIMEDIFF with TIME_TO_SEC. For example to check if two datetimes are between 10 seconds of each other
ABS(TIME_TO_SEC(TIMEDIFF(datetime1, datetime2))) < 10
ABS(TIMESTAMPDIFF(SECOND, datetime1, datetime2)) < 10
This allows for easily changing the units and it is now possible to do such comparisons using MICROSECOND as well.
精彩评论