1. Go to this page and download the library: Download kartik-v/yii2-date-range library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kartik-v / yii2-date-range example snippets
use kartik\daterange\DateRangePicker;
echo DateRangePicker::widget([
'model'=>$model,
'attribute'=>'datetime_range',
'convertFormat'=>true,
'pluginOptions'=>[
'timePicker'=>true,
'timePickerIncrement'=>30,
'locale'=>[
'format'=>'Y-m-d h:i A'
]
]
]);
use kartik\daterange\DateRangePicker;
echo DateRangePicker::widget([
'model'=>$model,
'attribute'=>'datetime_range',
'convertFormat'=>true,
'startAttribute'=>'datetime_min',
'endAttribute'=>'datetime_max',
'pluginOptions'=>[
'timePicker'=>true,
'timePickerIncrement'=>30,
'locale'=>[
'format'=>'Y-m-d h:i A'
]
]
]);
use kartik\daterange\DateRangeBehavior;
class UserSearch extends User
{
public $createTimeRange;
public $createTimeStart;
public $createTimeEnd;
public function behaviors()
{
return [
[
'class' => DateRangeBehavior::className(),
'attribute' => 'createTimeRange',
'dateStartAttribute' => 'createTimeStart',
'dateEndAttribute' => 'createTimeEnd',
]
];
}
public function rules()
{
return [
// ...
[['createTimeRange'], 'match', 'pattern' => '/^.+\s\-\s.+$/'],
];
}
public function search($params)
{
$query = User::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
$query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['>=', 'createdAt', $this->createTimeStart])
->andFilterWhere(['<', 'createdAt', $this->createTimeEnd]);
return $dataProvider;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.