Doctrine querybuilder DATE_FORMAT not working

DATE_FORMAT along with a bunch of Mysql function are not directly available in Doctrine.

To use them you can either create your own or add an extension like beberlei/DoctrineExtensions and then add the respective function to your doctrine bundle config like

doctrine:
    dbal:
        ....
    orm:
        ....
        dql:
            string_functions:
                DATE_FORMAT: DoctrineExtensions\Query\Mysql\DateFormat

Symfony 5 answer

Run

composer require beberlei/doctrineextensions

Add in

config/packages/doctrine.yaml

doctrine:
    orm:
        dql:
            datetime_functions:
                DATE_FORMAT: DoctrineExtensions\Query\Mysql\DateFormat

The same goes for other datetime functions:

doctrine:
    orm:
        dql:
            datetime_functions:
                DATE_FORMAT: DoctrineExtensions\Query\Mysql\DateFormat
                DAY: DoctrineExtensions\Query\Mysql\Day
                MONTH: DoctrineExtensions\Query\Mysql\Month
                YEAR: DoctrineExtensions\Query\Mysql\Year