Ankur Soni
Ankur Soni

Reputation: 6018

UPDATE using WHERE in Yii2 not working

I am checking for expiry in 'orders' table.

If 'end_date' is less or equal to Todays date, then I am changing status to "Expired". But I guess something is going wrong.

Below is the Piece of code.

$new_date = new \DateTime();
$today = $new_date->format('Y-m-d');
Orders::updateAll([ 'status' => 'Expired' ],'end_date <='.$today);

Also my DB snapshot below. Db has one value with date less than today.

Is my update query Correct?

enter image description here

Upvotes: 1

Views: 61

Answers (1)

Ankur Soni
Ankur Soni

Reputation: 6018

Well, I solved it using below piece of code change.

Orders::updateAll([ 'status' => 'Expired' ],'end_date <= :today',[':today' => $today]);

Upvotes: 1

Related Questions