Reputation: 25
I wrote a query in my Symfony that returns total sum of amounts per month of a year. But when I try to convert it from month number to month name it trows
Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ","
My code..
$resultYearly = $this->getTransactionRepository()
->createQueryBuilder('p')
->select('MONTH(p.transactionDate, \'%b\') AS MonthOfYear, sum(p.amount) Total')
MonthAndYear, sum(p.amount) Total')
->where('p.transactionDate >= :end')
->setParameter('end', new \DateTime('-1 year'))
->groupBy( 'MonthOfYear')
->getQuery()
->getArrayResult();
It works perfect with DATE_FORMAT but when I use MONTH it throws an error..
Upvotes: 1
Views: 68
Reputation: 1341
You need to remove the part of \'%b\'
from the Month
function, since MONTH
function takes only one parameter, which is date.
So your code should be:
$resultYearly = $this->getTransactionRepository()
->createQueryBuilder('p')
->select('MONTH(p.transactionDate) AS MonthOfYear, sum(p.amount) Total')
MonthAndYear, sum(p.amount) Total')
->where('p.transactionDate >= :end')
->setParameter('end', new \DateTime('-1 year'))
->groupBy( 'MonthOfYear')
->getQuery()
->getArrayResult();
Upvotes: 1