I have this list of time taken from mysql database:
2011-07-22 10:12:53
2011-07-22 10:17:53
2011-07-22 10:19:42
2011-07-22 10:29:31
Right now i want to get the closest date time from the bold date time. Only the date time after the bold one will be valid, and it must be the closest. So the desired result is 2011-07-22 10:19:42
How to solve this using php or mysql?
Thanks.
SELECT ABS(time_to_sec(timediff(col_with_date,'$date'))) AS time_distance FROM table_with_date ORDER BY time_distance LIMIT 1;
WHERE datefield < '2011-07-22 10:19:42'
ORDER BY datefield DESC
LIMIT 1
?