Im having a issue with comparing dates below is the code. it shows all rows even dates that have passed todays date. The Date field is set as date in sql.

$con = mysql_connect("localhost","myusername","mypassword");
if (!$con)
  die('Could not connect: ' . mysql_error());

mysql_select_db("mydatabase", $con);

$todays_date = date("Y-m-d");
$today = strtotime($todays_date);

$result = mysql_query("SELECT * FROM event where 'date' < $today");

   while ($row = mysql_fetch_array($result)) {
   echo "<tr>";
   echo "<td>" . $row['Id'] . "</td>";
   echo "<td>" . $row['Date'] . "</td>";
   echo "<td>" . $row['ArtistDate'] . "</td>";
   echo "<td>" . $row['Artist'] . "</td>";
   echo "<td>" . $row['ImagePath'] . "</td>";
   echo "<td>" . $row['ImgLink'] . "</td>";
   echo "<td>" . $row['IncFile'] . "</td>";
   echo "</tr>";

   echo "</table>";

Member Avatar

Try this SQL - backticks about the date - not single quotes. If you're using date format in DB, why using strtotime? date() should do everything you need.

SELECT * FROM event where `date` < '$today'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.