I need help with comparing two dates in php. The first date I am comparing is today's date and the other comes from the database. I tried using strtotime
but it only works when the database date is less than today's date, if the date is greater than today's date I have to compare the whole date, and and strtotime
does not work in that case.
Eg :
<?php
$today=date('d/m/y');
$expiry_date=$data['expiry'];
if(strtotime($expiry_date)<strtotime($today)){
echo "today is greater";
} else {
echo "expiry is greater";
// only gives the right result when database result is smaller than today
}
?>
other method :
$today=date('d/m/y');
$expiry_date=$data['expiry'];
if($expiry_date<$today)
{ echo "today is greater"; }
else
{echo "expiry is greater";} ?>` // only gives the right result when database result is greater than today