I have configured a date field appointment_date as datetime
field in mysql db.
In my model Appointment.php rules are set like this:
public function rules()
{
return [
[['appointment_date','weekdays'], 'safe'],
[['appointment_date'], 'date','format' => 'd-M-yyyy H:m'],
and in web.php under component I have set
'formatter' => [
'defaultTimeZone' => 'UTC',
'timeZone' => 'Asia/Kolkata',
and in my view I am trying to format the date for display like this:
[
Yii::$app->formatter->asDatetime('appointment_date')
],
Now I am getting the error -
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
)
Whereas the date stored in the database is like : 2015-01-20 11:50:00
If I am not formatting the date and simply keeping the attribute in view as
appointment_date
then the date is shown as 2015-01-20 11:50:00
I want to show the date as 20-01-2015 11:50:00
If I am using the code like this:
[
'attribute'=>'appointment_date',
'format'=>['DateTime','php:d-m-Y H:i:s']
],
I am getting the date formatted correctly.
I want to know What I am doing wrong here in using
Yii::$app->formatter->asDatetime('appointment_date')
Thanks