标签: php mysql
我需要在php中将一个日期如'2010-04-27'作为字符串,并在表格中找到最近的5个日期。表中的日期将保存为日期类型。
答案 0 :(得分:3)
您可以使用DATEDIFF + ABS
SELECT ABS(DATEDIFF(myfield,'2010-04-27')) AS diff FROM mytable ORDER BY diff LIMIT 5;
答案 1 :(得分:2)
你也可以查询差异,例如。
abs(datediff(date,$ date))
然后按此顺序