I need to get a date such as '2010-04-27' as a string in php and find the nearest 5 dates in a table. The date in the table are saved as a date type.
+3
A:
SELECT ABS(DATEDIFF(myfield,'2010-04-27')) AS diff FROM mytable ORDER BY diff LIMIT 5;
Haim Evgi
2010-08-30 10:57:36
Im getting 'is not a valid resource'
Will
2010-08-30 11:00:59
check this for "is not a valid resource":http://stackoverflow.com/questions/253378/not-a-valid-mysql-resource
Adam Butler
2010-08-30 11:12:45
This doesnt appear to be filling $row.while($row = mysql_fetch_array($result)) {The array row contains no column data
Will
2010-08-30 11:28:51
+2
A:
you could also query the difference eg. something like
abs(datediff(date, $date))
then order by this
Adam Butler
2010-08-30 10:58:53