PHP: Date larger than current date

I have this code:

$curdate = '22-02-2011';

$mydate = '10-10-2011';                     

if($curdate > $mydate)
{
    echo '<span class="status expired">Expired</span>';
}

This would echo expired BUT shouldn't because $mydate is in the future and therefore smaller than the $curdate but PHP is looking at JUST the first two numbers 22 and 10 instead of the whole string. How can I fix this?

Thanks


Try converting them both to timestamps first, and then compare two converted value:

$curdate=strtotime('22-02-2011');
$mydate=strtotime('10-10-2011');

if($curdate > $mydate)
{
    echo '<span class="status expired">Expired</span>';
}

This converts them to the number of seconds since January 1, 1970, so your comparison should work.


The problem is that your current variables are strings, and not time variables.

Try this out:

$curdate = strtotime('22-02-2011');

$mydate = strtotime('10-10-2011');  

$row_date = strtotime($the_date);
$today = strtotime(date('Y-m-d'));

if($row_date >= $today){
     -----
}

$currentDate = date('Y-m-d');

$currentDate = date('Y-m-d', strtotime($currentDate));

$startDate = date('Y-m-d', strtotime("01/09/2019"));

$endDate = date('Y-m-d', strtotime("01/10/2022"));

if (($currentDate >= $startDate) && ($currentDate <= $endDate)) {

    echo "Current date is between two dates";

} else {

    echo "Current date is not between two dates";  
}