Select with date = fails
I have the following select statement.
echo "<p>The Current Date Is: ".$the_date;
$query = "select * from `quiz` where quizdate = $the_date";
$result = $db->query($query);
$num_results = $result->num_rows;
$the_date contains the date I want, but the $query is failing, but the quiz table contains an entry with the same date...
I know dates can be tricky. The quizdate field is format date and it looks like:
You need single quotes around that date string in the query.
Also, if your column isn't a date but a datetime or timestamp, it won't be equal unless the time matches as well ('2009-05-01' will be treated as midnight on that date).
Thanks Dan, yes that was it !
& yes the field is a straight date field.