$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".
Example: <? php $date1 = new DateTime("18-02-24"); $date2 = new DateTime("2019-03-24"); if ($date1 > $date2) { echo 'datetime1 greater than datetime2'; } if ($date1 < $date2) { echo 'datetime1 lesser than datetime2'; } if ($date1 == $date2) { echo 'datetime2 is equal than datetime1'; } ?>
Comparing two dates in PHP is simple when both the dates are in the same format but the problem arises when both dates are in a different format. Method 1: If the given dates are in the same format then use a simple comparison operator to compare the dates. echo "$date1 is older than $date2" ; ?>
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
.
Or like this code:
$programs = Programs::find()->where('close_date >= :close_date', [':close_date' => $today])->all();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With