How to compare two dates in php [duplicate]

You will have to make sure that your dates are valid date objects.

Try this:

$date1=date('d/m/y');
$tempArr=explode('_', '31_12_11');
$date2 = date("d/m/y", mktime(0, 0, 0, $tempArr[1], $tempArr[0], $tempArr[2]));

You can then perform the strtotime() method to get the difference.

Leave a Comment