I set the definition_definition date field as datetime in mysql db.
In my model, the Appointment.php rules are set as follows:
public function rules() { return [ [['appointment_date','weekdays'], 'safe'], [['appointment_date'], 'date','format' => 'dM-yyyy H:m'],
and in web.php in the component I installed
'formatter' => [ 'defaultTimeZone' => 'UTC', 'timeZone' => 'Asia/Kolkata',
and, in my opinion, I am trying to format the date for display as follows:
[ Yii::$app->formatter->asDatetime('appointment_date') ],
Now I get the error message -
appointment_date' is not a valid date time value: DateTime::__construct(): Failed to parse time string (appointment_date) at position 0 (a): The timezone could not be found in the database Array ( [warning_count] => 1 [warnings] => Array ( [6] => Double timezone specification ) [error_count] => 3 [errors] => Array ( [0] => The timezone could not be found in the database [11] => Unexpected character [12] => Double timezone specification )
While the date stored in the database is similar: 2015-01-20 11:50:00
If I do not format the date and just save the attribute as appointment_date , then the date is displayed as 2015-01-20 11:50:00
I want to show the date as 20-01-2015 11:50:00
If I use this code:
[ 'attribute'=>'appointment_date', 'format'=>['DateTime','php:dmY H:i:s'] ],
I formatted the date correctly.
I want to know what I'm doing wrong here when using
Yii::$app->formatter->asDatetime('appointment_date')
thanks