Page 1 of 1

MySQL query question

Posted: Thu Sep 30, 2004 4:23 pm
by matthiasone
How would you write a query to find a record whose date field is closest to the current date?

8O

Posted: Thu Sep 30, 2004 4:27 pm
by feyd

Code: Select all

SELECT *, ABS(UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP( your_date_field )) `diff` FROM table ORDER BY `diff` LIMIT 1
I think