开发者

SQL Nearest Date

I need to ge开发者_如何学JAVAt a date such as '2010-04-27' as a string in php and find the nearest 5 dates in a table. The date in the table are saved as a date type.


you can use DATEDIFF + ABS

SELECT ABS(DATEDIFF(myfield,'2010-04-27')) AS diff FROM mytable ORDER BY diff LIMIT 5;


you could also query the difference eg. something like

abs(datediff(date, $date))

then order by this

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜