title: Symfony2 form datetime fields validation
body: <p>In my form I have two <code>datetime</code> fields: <code>startDate</code> and <code>endDate</code>. <code>startDate</code> can't be earlier than current time. <code>endDate</code> cant be earlier or equal to the <code>startDate</code> and it can't be more than one month from the <code>startDate</code>. </p>
  
  <p>So my question is how I could implement validation for those fields? I'm pretty new to Symfony so I would really appreciate if you could add and example of it.</p>
  
  <p>My form:</p>
  
  <pre><code>&lt;?php
  namespace Atotrukis\MainBundle\Form\Type;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Doctrine\ORM\EntityRepository;
  use Symfony\Component\Validator\Constraints as Assert;
  class CreateEventFormType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('name', 'text', [
                  'constraints' =&gt;[
                      new Assert\NotBlank([
                          'message' =&gt; "Renginio pavadinimas negali būti tuščias"
                      ]),
                      new Assert\Length([
                          'min' =&gt; "2",
                          'max' =&gt; "255",
                          'minMessage' =&gt; "Renginio pavadinimas negali būti trumpesnis nei {{ limit }} simboliai",
                          'maxMessage' =&gt; "Renginio pavadinimas negali būti ilgesnis nei {{ limit }} simboliai"
                      ])
                  ]
              ])
              -&gt;add('description', 'textarea', [
                  'constraints' =&gt;[
                      new Assert\NotBlank([
                          'message' =&gt; "Renginio aprašymas negali būti tuščias"
                      ]),
                      new Assert\Length([
                          'min' =&gt; "10",
                          'max' =&gt; "5000",
                          'minMessage' =&gt; "Renginio aprašymas negali būti trumpesnis nei {{ limit }} simbolių",
                          'maxMessage' =&gt; "Renginio aprašymas negali būti ilgesnis nei {{ limit }} simbolių"
                      ])
                  ]
              ])
              -&gt;add('startDate', 'datetime')
              -&gt;add('endDate', 'datetime')
              -&gt;add('map', 'text')
              -&gt;add('city', 'entity', array(
                  'class' =&gt; 'AtotrukisMainBundle:City',
                  'property' =&gt; 'name',
                  'constraints' =&gt;[
                      new Assert\NotBlank([
                          'message' =&gt; "Pasirinkite miestą"
                      ])
                  ],
                  'empty_value' =&gt; 'Pasirinkite miestą',
                  'query_builder' =&gt; function(EntityRepository $er) {
                      return $er-&gt;createQueryBuilder('c')
                          -&gt;addOrderBy('c.priority', 'ASC')
                          -&gt;addOrderBy('c.name', 'ASC');
                  },
              ))
              -&gt;add('save', 'submit', array('label' =&gt; 'Sukurti'));
      }
      public function getName()
      {
          return 'createEventForm';
      }
  }
  </code></pre>