How do I convert the following to active record style in yii2?
SELECT *
FROM orders
WHERE created_at >= (CURDATE() - INTERVAL 11 MONTH)
ORDER BY id DESC
What I have tried:
switch ($period) {
case 'y':
$p = "12 month";
break;
case 'm':
$p = "1 month";
break;
case 'w':
$p = "7 days";
break;
case 'd':
$p = "1 days";
break;
}
Customers::find()
->where('>=', 'created_at', (CURDATE() - INTERVAL $p))
->orderBy('id DESC');
But I get:
syntax error, unexpected '$p' (T_VARIABLE)