在php中比较两个日期的问题

For some reason I am having difficulties comparing a previous date and current date. I have tried many different things, and tried to google my way to an answer but with no luck.

This is how my code is..

$phpdate = date("Y-m-d");

$sql = "SELECT lastDailyCollect FROM users WHERE steamid='".$_POST['steamid']."'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $lastDailyCollect = $row['lastDailyCollect'];
    }
} 

if ($lastDailyCollect == $phpdate) {
//give user error message
}elseif ($lastDailyCollect != $phpdate) {
//let user know it suceeded
}else {
//comparison error
}

I want to check if the user is able to collect a daily bonus. The last collection date of each user is stored in a mysql database, in a table called users. It always goes to the comparison error.

Hope somebody can help.

What you can do to check if lastDailyCollect date was previous day by subtracting one day from the current date and storing it in $yesterday then matching if previous date is equal to lastDailyCollect date.

<?php

$date = date("Y-m-d");  //2017-05-12

$lastDailyCollect = "2017-05-11";

$yesterday = date('Y-m-d',strtotime($date . "-1 days")); //2017-05-11

if($lastDailyCollect == $yesterday) {
//give user error message
    echo 'lastDailyCollect is equal to Previous day';
}
else
{
//let user know it suceeded
echo 'lastDailyCollect is not equal to previous day';
}
?>