Answer the question
In order to leave comments, you need to log in
What am I doing wrong when selecting rows for the current month in Yii2?
Good afternoon !
With such a SQL query, right in phpMyAdmin, my line is
SELECT * FROM `brk_image_post_upload`
WHERE date > LAST_DAY(CURDATE()) + INTERVAL 1 DAY - INTERVAL 1 MONTH
AND date < DATE_ADD(LAST_DAY(CURDATE()), INTERVAL 1 DAY) AND juzer_id = 10;
$juzer_photo = $this->find()->where(['juzer_id' => 10])
->andWhere(['>', 'date', 'LAST_DAY(CURDATE()) + INTERVAL 1 DAY - INTERVAL 1 MONTH'])
->andWhere(['<', 'date', 'DATE_ADD(LAST_DAY(CURDATE()), INTERVAL 1 DAY)'])
->one();
//->andWhere('date > :date1',[':date1' => 'LAST_DAY(CURDATE()) + INTERVAL 1 DAY - INTERVAL 1 MONTH'])
//->andWhere('date < :date2',[':date2' => 'DATE_ADD(LAST_DAY(CURDATE()), INTERVAL 1 DAY)'])
Answer the question
In order to leave comments, you need to log in
1 thing you need to understand is in what format the date is in the database. If in the form of a date, not a number, then mysql like this:
And in yii2 using AR, it seems like this (but worth checking):
SomeModel::find()->andWhere("MONTH(`date`) = MONTH(NOW()) AND YEAR(`date`) = YEAR(NOW())")->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question