S
S
Silverviql2018-08-29 17:27:45
Yii
Silverviql, 2018-08-29 17:27:45

How to output data in yii2 mysql date span?

$dataProvider = new ActiveDataProvider([
    'query' => \app\models\Zakaz::find(
        ->where('action <= 0') ->andWhere( 'date >= 2018-04-01  AND date <= 2018-08-01')
       /* ->groupBy('date_close')*/,
    'pagination' => [
        'pageSize' => 20,
    ],
]);

Why the andWhere condition does not understand the value of dates, is stored in the database as 2018-06-19 10:30:51, etc.
just write DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) and subtract the month 2 months, etc. for me so nonsense , there should be a more convenient notation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-08-29
@Silverviql

Good evening.
You store the date along with the time.
So why not try this:
Although it's better to store the time in a timestamp, the field type in the table is integer.
UPD.

<code lang="php">
andWhere(['>=',  'date', strtotime('2018-04-01 00:00:00')])->andWhere(['<=', 'date', strtotime('2018-08-01 23:59:59')]);
</code>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question