YEAR function is not Working in Symfony 2

Haseena P A

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 ??

Ahmed Siouani

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Search Function in Symfony2 is not working

From Dev

Search Function in Symfony2 is not working

From Dev

Symfony 2 ParamConverter Not Working

From Dev

Symfony 2 ParamConverter Not Working

From Dev

HTML Formatting not working in symfony 2

From Dev

DATEDIFF not working in Symfony2

From Dev

Translations not working in Symfony2

From Dev

Symfony 2 - Translation not working (xliff)

From Dev

Symfony's Guard start() function not working

From Dev

Loop for atan2 function by year in R

From Dev

symfony2 reverse year order in date field

From Dev

Function as service in Symfony2

From Dev

Symfony 2 and Swiftmailer not working with file spooling

From Dev

Symfony2 Secure by IP not working

From Dev

Symfony2: routing with controller as a service not working

From Dev

Custom repository class in symfony 2 not working

From Dev

Working with date ranges in Elasticsearch and Symfony2

From Dev

Ajax url to action not working + Symfony2

From Dev

Cascaded persist not working (Doctrine ORM + Symfony 2)

From Dev

symfony2 (doctrine) currency constraint not working

From Dev

Symfony2 custom security voter not working

From Dev

Symfony2 postUpdate listener not working

From Dev

Why is my VarDumper not working in Symfony2

From Dev

Symfony2 Route annotation on class not working

From Dev

SYMFONY2: csv export with StreamedResponse not working

From Dev

UglifyJS not working in Symfony2 production environment

From Dev

getDoctrine() not working in FOSUserBundle symfony2

From Dev

Symfony2 PHPUnit Clock Mocking not working

From Dev

Symfony2 SoftDeleteable not working on QueryBuilder Delete