How to compare Dates from database in Yii2

yii2

$time = new \DateTime('now');
$today = $time->format('Y-m-d');
$programs=Programs::find()->where(['close_date' >= $today])->all();

This is code for today's programs whose close_date is greater than today's date. I am getting error:

"Invalid Parameter -yii\base\InvalidParamException Operator '1'
requires two operands".

Best Solution

If you want to write where condition as array the code should be like this:

$programs = Programs::find()->where(['>=', 'close_date', $today])->all();

Check official documentation for more details:

Additionally you can specify arbitrary operators as follows: A condition of ['>=', 'id', 10] will result in the following SQL expression: id >= 10.

Related Question