Answer the question
In order to leave comments, you need to log in
How to remove time from a date when getting data from a database model?
I tried to write in the query ->select('DATE_FORMAT(date, "%m-%Y") as data')
Gives an error SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `zakaz` WHERE (action <= 0) AND (data >= (CURDATE()-1) AND data < CURDATE()' at line 1
I need it to group the date.Now everything looks like this for me.It turns out to combine only if the time also matches.
$Articles = new ActiveDataProvider([
'query' => \app\models\Zakaz::find()
->where('action <= 0') ->andWhere('data >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)'),
'pagination' => [
'pageSize' => 20,
],
]);
<?php echo GridView::widget([
'dataProvider' => $Articles,
'showFooter' => true,
'filterModel'=>$searchModel,
/*'showPageSummary'=>true,*/
'pjax'=>true,
'striped'=>true,
'hover'=>true,
'panel'=>['type'=>'primary', 'heading'=>'За неделю'],
'columns' => [
[
'attribute'=>'data',
'width'=>'310px',
'value'=>function ($model, $key, $index, $widget) {
return $model->data;
},
'filterType'=>GridView::FILTER_SELECT2,
'filter'=>ArrayHelper::map(\app\models\Zakaz::find()->orderBy('data')->asArray()->all(), 'id_zakaz', 'data'),
'filterWidgetOptions'=>[
'pluginOptions'=>['allowClear'=>true],
],
'filterInputOptions'=>['placeholder'=>'Any supplier'],
'group'=>true, // enable grouping
],
[
'class' => NumberColumn::className(),
'attribute' => 'fact_oplata',
],
],
]);;?>
Answer the question
In order to leave comments, you need to log in
removing the time from the date is not at the level of the SQL query, but at the level of data output in the GridView
...
'columns' => [
[
'attribute' => 'date',
'format' => ['date', 'php:d-m'-y]
]
...
->select('DATE_FORMAT(date, "%m-%Y") as data')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question