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

A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
SELECT *, ABS(UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP( your_date_field )) `diff` FROM table ORDER BY `diff` LIMIT 1