I have a database where dates were incorrectly formatted (so they are stored as varchar). Now I want to be able to only display dates from the past (including today).
I have found the mysql functions str_to_date and datediff, and have been trying to construct a mysql query which will combine them (using now() as the second date for datediff).
So far this has been a miserable failure. I'm quite new to php and mysql, and I'm not at all sure that what I am trying to do is even possible.
The table is called 'dates' and the column with the (wrongly formatted, e.g. 31/06/2009) date is called 'date'.
Here is the relevant piece of code - although I have been through several versions:
$query = "SELECT date FROM dates WHERE ((DateDiff(STR_TO_DATE('date', '%d/%M/%Y'),NOW())) <= 0)";
$result = mysql_query($query, $dbh);
while($row = mysql_fetch_row($result))
PS wasn't sure if this should be in PHP forum instead.
Apologies: did not see the mySQL forum there until after posting, sorry. Is it possible for a moderator to move this?