title: Unable to transform value for property path : Expected a \DateTime or \DateTimeInterface
body: <p>First of all: I'm pretty new to Symfony/programming and have problems finding the solution I need. </p>
  
  <p>I have these variables in my 'Event' Entity with standard getters and setters.:</p>
  
  <pre><code> /**
   * @var \DateTime
   *
   * @ORM\Column(name="startTime", type="time", nullable=true)
   *
   * @Assert\Expression(
   *     "this.getStartTime() &lt;= this.getEndTime()",
   *     message="Start time should be less or equal to end date!"
   * )
   */
  private $startTime;
  
  /**
   * @var \DateTime
   *
   * @ORM\Column(name="endTime", type="time", nullable=true)
   *
   * @Assert\Expression(
   *     "this.getEndTime() &gt;= this.getStartTime()",
   *     message="End time should be greater or equal to start time!"
   * )
   */
  private $endTime;
  </code></pre>
  
  <p>I have this Controller for my form:</p>
  
  <pre><code>&lt;?php
  
  
  namespace AppBundle\Controller;
  
  
  use AppBundle\Entity\Event;
  use AppBundle\Form\EventCreateFormType;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\Routing\Annotation\Route;
  
  class EventController extends Controller {
  
  /**
   * @Route("/eventmanager", name="event")
   */
  public function eventsAction(Request $request)
  {
      $events = $this-&gt;getDoctrine()// query database and get all events
      -&gt;getRepository('AppBundle:Event')
          -&gt;findAll();
  
      $event = new Event();
  
      $adminstatus = false;
  
      if (in_array('ROLE_ADMIN', $this-&gt;getUser()-&gt;getRoles())) {
          $adminstatus = true;
      }
      $event = $this-&gt;get('holiday.service')-&gt;createEventForm($request);
      $form = $this-&gt;createForm(EventCreateFormType::class, $event, array('rolestatus' =&gt; $adminstatus));
  
  
      if ($form-&gt;isValid()) {
  
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $em-&gt;persist($event);
          $em-&gt;flush();
  
          return $this-&gt;redirectToRoute('event'); // redirect to route: events
      }
  
      return $this-&gt;render('default/eventmanager.html.twig', array('events' =&gt; $events, 'form' =&gt; $form-&gt;createView()));
  }
  </code></pre>
  
  <p>With this type:</p>
  
  <pre><code>&lt;?php
  
  
  namespace AppBundle\Form;
  
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  use Symfony\Component\Form\Extension\Core\Type\TextType;
  use Symfony\Component\Form\Extension\Core\Type\TimeType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  
  class EventCreateFormType extends AbstractType {
  
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      parent::buildForm($builder, $options);
  
      $builder
          -&gt;add('title', TextType::class, array(
              'label' =&gt; 'event.form.title.label',
              'attr' =&gt; array(
                  'maxlength' =&gt; 75,
                  '' =&gt; '')
          ))
          -&gt;add('dateOf', TextType::class, array(
              'label' =&gt; 'event.form.dateOf.label',
  //                'widget' =&gt; 'single_text',
  //                'html5' =&gt; false,
              'attr' =&gt; [
                  'class' =&gt; 'js-datepicker',
  //                    'format' =&gt; 'dd-MM-yyyy',
              ],
          ))
          -&gt;add('startTime', TimeType::class, array(
              'label' =&gt; 'event.form.startTime.label',
          ))
          -&gt;add('endTime', TimeType::class, array(
              'label' =&gt; 'event.form.endTime.label',
          ))
          -&gt;add('notice', TextareaType::class, array(
              'label' =&gt; 'event.form.notice.label',
              'required' =&gt; false,
              'attr' =&gt; array('maxlength' =&gt; 2500)
          ));
      if ($options['rolestatus'] == true) {
          $builder-&gt;add('status', ChoiceType::class, array(
              'label' =&gt; 'event.form.status.label',
              'data' =&gt; $options['rolestatus'],
              'choices' =&gt; array(
                  'event.form.status.public' =&gt; true,
                  'event.form.status.private' =&gt; false
              ),
              'choices_as_values' =&gt; true
          ));
      }
      $builder-&gt;add('save', SubmitType::class, array(
          'label' =&gt; 'event.form.create.button'
      ));
  
  
  }
  
  public function configureOptions(OptionsResolver $resolver)
  {
      $configs = $resolver-&gt;getDefinedOptions();
      $configs[] = 'rolestatus';
      $resolver-&gt;setDefined($configs);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And this service:</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Controller\Services;
  
  use AppBundle\Entity\Event;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\Request;
  
  class HolidayServiceController extends Controller {
  
  
  
  public function createEventForm(Request $request) {
  
      $submittedForm = $request-&gt;get('event_create_form');
      $adminstatus = false;
      if (in_array('ROLE_ADMIN', $this-&gt;getUser()-&gt;getRoles())) {
          $adminstatus = true;
      }
      dump($submittedForm);
  
      $event = new Event();
      if (!empty($submittedForm)) {
  
              $creator = $this-&gt;getUser();
              $title = $submittedForm['title'];
              $startTime = $submittedForm['startTime'];
              $endTime = $submittedForm['endTime'];
              $notice = $submittedForm['notice'];
              $now = new\DateTime();
              $dateOf = new \DateTime();
              $explodedDate = explode('-', $submittedForm['dateOf']);
              $dateOf-&gt;setDate($explodedDate[2], $explodedDate[1], $explodedDate[0]);
  
              $event-&gt;setTitle($title);
              $event-&gt;setDateOf($dateOf);
              $event-&gt;setStartTime($startTime);
              $event-&gt;setEndTime($endTime);
              $event-&gt;setNotice($notice);
              $event-&gt;setCreator($creator);
              $event-&gt;setCreatedAt($now);
              if (!empty($submittedForm) &amp;&amp; $adminstatus == true) {
                  $status = $submittedForm['status'];
                  $event-&gt;setStatus($status);
              } else {
                  $event-&gt;setStatus(false);
              }
              return $event;
          }
      return $event;
  
  
  }
  }
  </code></pre>
  
  <p>Now, when i try to create a new Event I get following error:</p>
  
  <p>Unable to transform value for property path "startTime": Expected a \DateTime or \DateTimeInterface.
  500 Internal Server Error - TransformationFailedException</p>
  
  <p>I know that this is happening because I'm passing an array of startTime but not an object.</p>
  
  <p>What do I have to change to accomplish that?</p>
  
  <p>thx in advance.</p>