title: Doctrine 2.2 Datetime string conversion in Symfony 3.4
body: <p>I am troubleshooting a search bar to return rows within a period chosen from 'To' and 'From' datepickers.</p>
  
  <p>I initially got this error :</p>
  
  <blockquote>
    <p>Error: Method Doctrine\ORM\Query\Expr\Comparison::__toString() must not throw an exception, caught Symfony\Component\Debug\Exception\ContextErrorException: Catchable Fatal Error: Object of class DateTime could not be converted to string</p>
  </blockquote>
  
  <p>I converted the relevant query to a string using ->format() function:</p>
  
  <pre><code>            if (is_array($value) &amp;&amp; isset($value['to'])) {
  
              $to = \DateTime::createFromFormat('d/m/Y H:i:s', $value['from'] . ' 23:59:59');
              var_dump($value, $to);die;
              if ($to &lt;&gt; false) {
                  $query-&gt;andWhere(
                          $query-&gt;expr()-&gt;lte($path, $to-&gt;format('Y-m-d H:i:s'))
                  );
              }
          }
  </code></pre>
  
  <p>Now doctrine throws the following error:</p>
  
  <blockquote>
    <p>[Syntax Error] line 0, col 977: Error: Expected end of string, got '00'</p>
  </blockquote>
  
  <p>Is there something else I need to do to format the date to make it acceptable to the querybuilder? I've tried using / instead of : but this causes an issue.</p>