Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP find by date range?

I'm trying to fetch coupons that haven't expired yet. I have this in my controller:

public function coupons() {
    $this->paginate['Coupon']=array(
        'limit'=>9,
        'order'=>'RAND()',
        'conditions'=>array(
        'Coupon.end_date'=>??????)
    );
    $c=$this->paginate('Coupon');
    $this->set('allcoupons', $c);
}

I need it to return all records not expired as of today. end_date is in DATE format. I don't know how to ask cake to look at end_date and compare it to today, AND do it inside the paginate method.

like image 847
huzzah Avatar asked May 20 '26 09:05

huzzah


1 Answers

You just need to format your date properly

'Coupon.end_date >' => date('Y-m-d H:i:s')
like image 138
Nathan Gaskin Avatar answered May 23 '26 00:05

Nathan Gaskin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!