Not able to use YEAR() in symfony 2 doctrine..My code is given below
$users = $this->getEntityManager()
->createQuery("SELECT YEAR(u.dob) from AcmeDemoBundle:AppUsers u")
->getResult();
While running this code,it shows the following error
[Syntax Error] line 0, col 7: Error: Expected known function, got 'YEAR'
Why this happen ??
The mapping for this function (and many others for managing datetime elements) does not exist in doctrine. You've to use DoctrineExtensions and add the following mapping to your configuration,
# Doctrine Configuration
doctrine:
orm:
dql:
datetime_functions:
year: DoctrineExtensions\Query\Mysql\Year
You can also map it to a function of your own with a bit of more work.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments