Reputation: 177
I have in my gridview a date. I want to type it in the format "29.11.2018"
. But in my table, the date is in the format "2018-11-29"
.
So it doesnt filter.
my index.php:
[
'attribute'=>'enddate',
'format' => 'date',
'label' => 'Ablaufdatum'
],
my searchmodel:
$query->andFilterWhere(['like', 'user', $this->user])
->andFilterWhere(['like', 'enddate', $this->enddate]);
Upvotes: 3
Views: 2326
Reputation: 23738
You can use mysql:DATE_FORMAT()
AND php:date()
to make sure it always compares in the same format and you can use any of the =
,>
,<
,>=
,<=
operators rather than like
.
Change the below code
$query->andFilterWhere(['like', 'user', $this->user])
->andFilterWhere(['like', 'enddate', $this->enddate]);
to
$query->andFilterWhere(['like', 'user', $this->user])
->andFilterWhere(
[
'=',
new \yii\db\Expression('DATE_FORMAT(enddate, "%d.%m.%Y")'),
date('d.m.Y', strtotime($this->enddate)),
]
);
Upvotes: 4
Reputation: 42093
You can try something like this before filter:
date( 'Y-m-d', strtotime( $this->enddate ) );
Upvotes: 0