I want to compare a date is between two given dates or not and return the result. My logic is correct but I am unable to figure out why the statement is returning even if the date is exists in between two given dates. Can any one help me please?
Please remember the dates has to be in us format. The dates values assigned to $fromDate and $toDate coming from database but I just hardcoded them here for simplicity.
class Insurance {
public $fromDate = '2019-10-01';
public $toDate ='2020-10-01';
public function checkDate($date) {
$date = date('m-d-Y',strtotime($date));
$fromDate = date('m-d-Y',strtotime($this->fromDate));
$toDate = date('m-d-Y',strtotime($this->toDate));
if(($date >= $fromDate) && ($date <= $toDate)) {
return 'Yes';
} else {
return 'No';
}
}
}
$insuranace = new Insurance(1);
echo $insuranace->checkDate('01-01-2020');