I need to get the closest date to current date from a MySQL table.
This is my table:
id | date | name 1 | 2012-10-29 | tes
SELECT * FROM `your_table` WHERE ABS(DATEDIFF(`date`, NOW()));
Returns:
'1', '2012-10-29 00:00:00', 'test'
SELECT * FROM your_table ORDER BY ABS(DATEDIFF(NOW(), `date`)) LIMIT 1
select top 1 date from table where date > now() order by date desc