luminous Posted January 5, 2010 Share Posted January 5, 2010 Hi, I have a single table which contains a value of 'startdate' how do I return a value which the startdate is closest to the current date past or future? I've tried: SELECT * FROM exhibitions WHERE (UNIX_TIMESTAMP('CURDATE')=UNIX_TIMESTAMP(exhibitions.startdate)) But this seems to return all fields with the same year. The type in the table for startdate is 'date' Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/187315-matching-closest-to-current-date/ Share on other sites More sharing options...
kickstart Posted January 5, 2010 Share Posted January 5, 2010 Hi Maybe SELECT *, ABS(DATEDIFF(NOW(),exhibitions.startdate)) AS daysDifference FROM exhibitions ORDER BY daysDifference LIMIT 1 All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/187315-matching-closest-to-current-date/#findComment-989200 Share on other sites More sharing options...
luminous Posted January 6, 2010 Author Share Posted January 6, 2010 Hey Keith, That seems to of done it! Just wondering quickly would it be easy to implement so it only matches the nearest too current event with multiple dates in the future? Quote Link to comment https://forums.phpfreaks.com/topic/187315-matching-closest-to-current-date/#findComment-989273 Share on other sites More sharing options...
luminous Posted January 6, 2010 Author Share Posted January 6, 2010 Nevermind SELECT * , ABS( DATEDIFF( NOW( ) , exhibitions.startdate ) ) AS daysDifference FROM exhibitions WHERE exhibitions.startdate > NOW( ) ORDER BY daysDifference LIMIT 1 seems to have done the jobs. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/187315-matching-closest-to-current-date/#findComment-989274 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.