I'm using Kartiks DateRangePicker with the `presetDropdown' option. This gives some default values to search on, today, yesterday, last 7 days etc.
The code to produce the picker:
echo DateRangePicker::widget([
'model'=>$model,
'attribute' => 'created_at',
'useWithAddon'=>true,
'convertFormat'=>true,
'presetDropdown'=>true,
'hideInput'=>true,
'startAttribute' => 'start',
'endAttribute' => 'end',
'pluginOptions'=>[
'locale'=>['format' => 'Y-m-d'],
]
]);
SearchItem class:
$this->start = strtotime($this->start);
$this->end = strtotime($this->end);
$query->andFilterWhere(['>=', 'created_at', $this->start])
->andFilterWhere(['<', 'created_at', $this->end]);
The problem I'm having is when using today
or yesterday
options it produces the following query:
SELECT * FROM `item` WHERE (`created_at` >= 1534896000) AND (`created_at` < 1534896000)
So it is querying for items that are created bang on 12am. Does anyone have any ideas what it could be, pretty sure its not the default behavior so must be something I'm doing wrong.