I have an events table and need to pull the 4 closest dates to tod开发者_如何学Pythonay's date and they can be in the past, present or future.
What would the SQL (using MySQL) be for this if it is possible?
Thanks
Brett
I don't know which DB you are using, but this works with mysql:
select *
from event
order by abs(datediff(event_date, now()))
limit 4
Try using the TIMEDIFF
function like this:
select *
from events
order by abs(timediff(now(), yourdatecolumn))
limit 4;
精彩评论