I am trying to get all rows in a database which have been created between two dates inclusively. When I search for meetings in 2013-05-01 and todays date, I get no results but when I search without the WHERE clause I see there are two records for today. I thought, since the dates are DATETIME, I would try casting them as dates but this doesn't seem to work.
My function is as follows:
function meeting_reports($connection, $to, $from)
{
$status = array();
$sql =
$connection->query (
"SELECT `meeting_id`,`visibility`,`meeting_start`
FROM `details`
WHERE DATE(`meeting_start`) BETWEEN '{$from}' AND '{$to}'"
);
$status["total_meetings"] = 0;
$status["cancelled_meetings"] = 0;
if($sql->num_rows > 0)
{
while($results = $sql->fetch_assoc())
{
if($results["visibility"]==0)
{
$status["total_meetings"]++;
}
elseif($results==1)
{
$status["total_meetings"]++;
}
elseif($results["visibility"]==2)
{
$status["total_meetings"]++;
}
elseif($results["visibility"]==3)
{
$status["cancelled_meetings"]++;
}
}
}
return $status;
}
What am I doing wrong?