How to compare two dates & update model data in Yii
<p>I have a model named BloodRequest. When any new record has been made in this model, the status of the record is defined as "active". Now, I am trying to make a controller in Yii 1.1 which will check if the date saved in "required_on" older than two months. If it is older than two months, the status will be updated to "inactive". </p>

<p>PROBLEM: I have made the controller and it updates the status. But it updates all the status to inactive, instead of updating records which are older than two months. I have been trying to find where is the problem but couldn't. Everything is okay as I can see. The code of the action of the controller is given below:</p>

<pre><code>public function actionRequest() {

//save all the record in an array
    $model = BloodRequest::model()-&gt;findAll();


    foreach ($model as $key) {
        $id = $key['id'];
        $date = date("YYYY-MM-DD", strtotime($key['required_on']));

//check the date and update status

        if (strtotime('-60 days') &gt; strtotime($date)) {
            $found = BloodRequest::model()-&gt;findByPk($id);

            $found-&gt;status = "active";
            if($found-&gt;validate())
            {
                $found-&gt;save();
            }


        }
    }




    $this-&gt;render('request');
}
}
</code></pre>