DateTime

Validates that a value is a valid “datetime”, meaning either a DateTime object or a string (or an object that can be cast into a string) that follows a valid YYYY-MM-DD HH:MM:SS format.

Applies to property or method
Options
Class Symfony\Component\Validator\Constraints\DateTime
Validator Symfony\Component\Validator\Constraints\DateTimeValidator

Basic Usage

  • YAML
    # src/Acme/BlogBundle/Resources/config/validation.yml
    Acme\BlogBundle\Entity\Author:
        properties:
            createdAt:
                - DateTime: ~
    
  • Annotations
    // src/Acme/BlogBundle/Entity/Author.php
    namespace Acme\BlogBundle\Entity;
    
    use Symfony\Component\Validator\Constraints as Assert;
    
    class Author
    {
        /**
         * @Assert\DateTime()
         */
         protected $createdAt;
    }
    

Options

message

type: string default: This value is not a valid datetime

This message is shown if the underlying data is not a valid datetime.