I want to use a date in my formbuilder.
When I dump the variable $date
I get the output:
DateTime @1536139353 {#2479 ▼
date: 2018-09-05 11:22:33.0 Europe/Paris (+02:00)
}
When I try to use it now in my formbuilder like this:
$options['format'] = 'dd.MM.yyyy';
$options['data'] = new \DateTime($date);
Then I get an error message:
DateTime::__construct() expects parameter 1 to be string, object given
$date
is already a datetime:
DateTime @1536139353 {#2479 ▼
date: 2018-09-05 11:22:33.0 Europe/Paris (+02:00)
}
So there is no need to convert it like this new \DateTime($date);
The solution is:
$options['format'] = 'dd.MM.yyyy';
$options['data'] = $date;