title: Doctrine2: Use date functions in QueryBuilder
body: <p>I want to know how to use date functions like <code>WEEK</code> or <code>MONTH</code> in query builder. I'm using Zend not Symfony. When I try my current code with WEEK I get this error:</p>
  
  <pre><code>Error: Expected known function, got 'WEEK'
  </code></pre>
  
  <p><strong>This is my current code:</strong></p>
  
  <pre><code>&lt;?php
    namespace Repositories;
    use Doctrine\ORM\EntityRepository;
    /**
     * Analytic
     *
     * This class was generated by the Doctrine ORM. Add your own custom
     * repository methods below.
     */
    class Analytic extends EntityRepository {
      public function getSocialAnalytics($type){
        $response = false;
        if($type){
          $qb = $this-&gt;_em-&gt;createQueryBuilder();
          $qb
            -&gt;select('a')
            -&gt;from('\Entities\Analytic', 'a');
          $qb-&gt;where(' a.type = :type ');
          $qb-&gt;andWhere(' WEEK(NOW()) = WEEK(created) ');
          $qb-&gt;setParameter('type', $type);
          $response =  $qb-&gt;getQuery()-&gt;getResult(\Doctrine\ORM\Query::HYDRATE_OBJECT);
        }
        return $response;
      }
    }
  </code></pre>
  
  <p>This is my configuration:</p>
  
  <pre><code>// Custom resource plugins inherit this sweet getOptions() method which will retrieveenter code here
            // configuration settings from the application.ini file
        $config = new Zend_Config($this-&gt;getOptions());
  
        // Define the connection parameters
        $options = array(
            'connection' =&gt; array(
            'driver'   =&gt; "{$config-&gt;connection-&gt;driver}",
            'host'     =&gt; "{$config-&gt;connection-&gt;host}",
            'dbname'   =&gt; "{$config-&gt;connection-&gt;dbname}",
            'user'     =&gt; "{$config-&gt;connection-&gt;user}",
            'password' =&gt; "{$config-&gt;connection-&gt;password}"
          )
        );
  
        $configEm = new \Doctrine\ORM\Configuration;
  
        $cache = new \Doctrine\Common\Cache\ArrayCache;
  
        $driverImpl = $configEm-&gt;newDefaultAnnotationDriver(
          $config-&gt;connection-&gt;entities
        );
  
        $configEm-&gt;setMetadataCacheImpl($cache);
  
        $configEm-&gt;setMetadataDriverImpl($driverImpl);      
  
        // Configure proxies
  
        $configEm-&gt;setAutoGenerateProxyClasses(
          $config-&gt;connection-&gt;proxies-&gt;generate
        );      
  
        $configEm-&gt;setProxyNamespace($config-&gt;connection-&gt;proxies-&gt;ns);      
  
        $configEm-&gt;setProxyDir(
          $config-&gt;connection-&gt;proxies-&gt;location
        );      
  
        // Configure cache
  
        $configEm-&gt;setQueryCacheImpl($cache);
  
        $em = \Doctrine\ORM\EntityManager::create($options['connection'], $configEm);
        Zend_Registry::set('em', $em);
  
        return $em;
  </code></pre>