Repository/BaseOrderRepository.php
public function findByMonth($month, $state)
    {
        $emConfig = $this->getEntityManager()->getConfiguration();
        $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
        $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
        //$emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');

        $today = getdate();
        $month = $today['mon'];
        $year = $today['year'];

        if($month == 'previous')
        {
            $month--;
            if($month == 0)
            {
                $month = 12;
                $year--;
            }
        }

        $qb = $this->createQueryBuilder('o');
        $qb
            ->where('YEAR(o.createdAt) > :year and MONTH(o.createdAt) = :month and o.createdAt and o.state = 2')
            ->setParameter('month', $month)
            ->setParameter('year', $year);

        return $qb
            ->getQuery()
            ->getResult()
            ;
    }
public function findByMonth($month, $state)
    {
        $emConfig = $this->getEntityManager()->getConfiguration();
        $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
        $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
        //$emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');

        $today = getdate();
        $month = $today['mon'];
        $year = $today['year'];

        if($month == 'previous')
        {
            $month--;
            if($month == 0)
            {
                $month = 12;
                $year--;
            }
        }

        $qb = $this->createQueryBuilder('o');
        $qb
            ->where('YEAR(o.createdAt) > :year and MONTH(o.createdAt) = :month and o.createdAt and o.state = 2')
            ->setParameter('month', $month)
            ->setParameter('year', $year);

        return $qb
            ->getQuery()
            ->getResult()
            ;
    }
@param $month
@param $state

@return array