Date ==== Validates that a value is a valid date, meaning a string (or an object that can be cast into a string) that follows a valid ``YYYY-MM-DD`` format. ========== =================================================================== Applies to :ref:`property or method ` Options - `groups`_ - `message`_ - `payload`_ Class :class:`Symfony\\Component\\Validator\\Constraints\\Date` Validator :class:`Symfony\\Component\\Validator\\Constraints\\DateValidator` ========== =================================================================== Basic Usage ----------- .. configuration-block:: .. code-block:: php-annotations // src/Entity/Author.php namespace App\Entity; use Symfony\Component\Validator\Constraints as Assert; class Author { /** * @Assert\Date * @var string A "Y-m-d" formatted value */ protected $birthday; } .. code-block:: yaml # config/validator/validation.yaml App\Entity\Author: properties: birthday: - Date: ~ .. code-block:: xml .. code-block:: php // src/Entity/Author.php namespace App\Entity; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Mapping\ClassMetadata; class Author { /** * @var string A "Y-m-d" formatted value */ protected $birthday; public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('birthday', new Assert\Date()); } } .. include:: /reference/constraints/_empty-values-are-valid.rst.inc Options ------- .. include:: /reference/constraints/_groups-option.rst.inc ``message`` ~~~~~~~~~~~ **type**: ``string`` **default**: ``This value is not a valid date.`` This message is shown if the underlying data is not a valid date. You can use the following parameters in this message: =============== ============================================================== Parameter Description =============== ============================================================== ``{{ value }}`` The current (invalid) value =============== ============================================================== .. include:: /reference/constraints/_payload-option.rst.inc