Answer the question
In order to leave comments, you need to log in
How to format date in Unix in ModelSearch yii2?
I am using kartik's DatePicker widget to search the gridView through the standard ModelSearch that gii creates, the widget creates a get request like
http://test.local/news?NewSearch=&NewSearch[createDate]=2021-05-20
public function actionIndex()
{
$searchModel = new NewsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
$query->andFilterWhere([
'id' => $this->id,
'createDate' => strtotime($this->createDate),
]);
<?php
echo '<label class="control-label">Дата создания</label>';
echo DatePicker::widget([
'model' => $model,
'attribute' => 'createDate',
'attribute2' => 'createDate',
'options' => ['placeholder' => 'От'],
'options2' => ['placeholder' => 'До'],
'type' => DatePicker::TYPE_RANGE,
'pluginOptions' => [
'format' => 'yyyy-mm-dd',
'autoclose' => true,
]
]);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question