I have a VARCHAR column in my mysql database that stores dates with commas rather than hyphens.
I want to fetch some data by comparing these dates against the current date. To get the current date, I am using the php5 method date("Y,m,d");
and declaring it as $date;
If the current date is less than a given row's date, then I want to retrieve it otherwise omit it from the resultset.
Here is my code
$date=date("Y,m,d"); //current date to check if expiry date is valid or not
try {
$conn = new PDO("mysql:host=******;dbname=******", $username, "******");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "select id, discount, expirydate, description, logouploader from table WHERE expirydate>= ? LIMIT 10";
$statement = $conn->prepare($query);
$statement->execute(array($date));
foreach($statement->fetchAll(PDO::FETCH_ASSOC) as $row) {
echo $row['expirydate'];
}
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
$conn = null;
My code does not compare dates; it fetches all rows even though it was supposed to leave those records which are less than $date;
// current date
How can I filter my resultset to only return rows which are not yet expired?