Asfi Tanoli Asfi Tanoli - 5 months ago 32
PHP Question

How to show data with less than current date in yii?

How do i filter the date which is less than the current date?

Company::model()->with(array(
'Bundles'=>array(
'condition'=>'Bundles.status=1',
'order'=>'payment_date DESC',
),
))->findByPk($company_id);


Currently above code is displaying all data whose
status = 1


but i want to show the data whose
expiry_date
should be less than current date. How can i achieve this?

This is what i have tried so far but NO success.

Company::model()->with(array(
'Bundles'=>array(
'condition'=>'Bundles.expiry_date < date("Y-m-d H:i:s")',
'order'=>'payment_date DESC'
),
))->findByPk($company_id);

Answer

You can try something like this.

Company::model()->with(array(
            'Bundles'=>array(
                'condition'=>'Bundles.expiry_date < CURDATE()',
                'order'=>'payment_date DESC'
            ),
        ))->findByPk($company_id);

You cannot put php date function into SQL statement in the way u did it. Try to use CURDATE()