title: Symfony and Doctrine: order by time difference
body: <p>I am trying to build a query that retrieves all the most recent and upcoming activities from database.</p>
  
  <p>The entity <code>activity</code> has a field named <code>date</code> of type <code>DateTime</code>. So in my repository I was thinking of building something like this:</p>
  
  <pre><code>$query = $repository
            -&gt;createQueryBuilder('a');
  $query-&gt;orderBy( 'DATEDIFF( a.date, NOW())' , 'ASC');
  $query-&gt;setMaxResults( 6 );
  return $query;
  </code></pre>
  
  <p>Unfortunately I get the following error:</p>
  
  <pre><code>[Syntax Error] line 0, col 59: Error: Expected end of string, got '('
  </code></pre>
  
  <p>The Dql that is generated by my query:</p>
  
  <pre><code>SELECT a FROM MyBundle\Entity\Activity a ORDER BY DATEDIFF( a.date, NOW()) ASC
  </code></pre>
  
  <p>I also tried installing <code>beberlei/DoctrineExtensions</code>, but either it is not working or I was unable to configure it correctly.</p>
  
  <p>Anyone has any suggestion?
  Thanks in advance</p>