Date Validator - Timestamp

I am having a problem with the dateValidator.

Yii::$app->params[‘datePickerFormat’] = ‘mm/dd/yyyy’;




        [['birth_date', 'aniversary_date', 'hire_date'], 'default', 'value' => null],

        [['birth_date'], 'date',

            'format' => Yii::$app->params['datePickerFormat'],

            'timestampAttribute' => 'birth_date',

        ],

        [['aniversary_date'], 'date',

            'format' => Yii::$app->params['datePickerFormat'],

            'timestampAttribute' => 'aniversary_date',

        ],



always give me the current month/correct day/correct year for both attributes in the DetailView.




        DetailView::widget([

            'model' => $model,

            'attributes' => [

                [

                    'attribute' =>'birth_date',

                    'format'=>['date', 'php:F jS'],

                ],

                'aniversary_date:date',

            ],

        ]);



The value of Yii::$app->params[‘datePickerFormat’] is what is needed for the dosamigos\datepicker\DatePicker.




    $form->field($model, 'birth_date')->widget(DatePicker::className(), [

        'options' => [

            'placeholder' => Yii::$app->params['datePickerFormat'],

        ],

        'clientOptions' => [

            'autoclose' => true,

            'format' => Yii::$app->params['datePickerFormat'],

            //'startDate' => '-1d',

            'clearBtn' => true,

            'todayBtn' => true,

            'todayHighlight' => true,

        ]

    ]);



If I take out the ‘format’=> in the rule, the date fails to validate. I even tried to use ‘php:’.Yii::$app->params[‘datePickerFormat’] in the rule[] and still fails to validate.

However when I go back to the form the dates are correct. What am I doing wrong? Any help would be appreciated.

For the model’s rules section date format should be specified like this:


public function rules()

{

    return [

       ...

       ['birth_date', 'date', 'format' => 'MM/dd/yyyy'],

       ['birth_date', 'date', 'format' => 'php:m/d/Y'], //alternatively you can specify the format in PHP style

       ...

    ];

}

You should use MM (uppercase) for month. Lowercase mm is for minutes.