Why do I receive "This value should be of type string" when using a DateTime constraint on Symfony 5?
You are using the wrong of assertion.
Date
expects a string or an object that can be cast into a string. And a DateTimeInterface
is neither.
You should be using a Type
constraint.
/** * @Assert\Type("\DateTimeInterface") */ private $createdAt;
The ability to use Assert\Date
to validate DateTime
objects was deprecated on Symfony 4.2, and on Symfony 5.0 it was removed altogether.