You can add Doctrine extension so you can use the MySql YEAR
and MONTH
statement by adding this configuration if you’re on Symfony:
doctrine:
orm:
dql:
string_functions:
MONTH: DoctrineExtensions\Query\Mysql\Month
YEAR: DoctrineExtensions\Query\Mysql\Year
now you can use the MONTH and YEAR statements in your DQL or querybuilder.
Note: The extension supports MySQL, Oracle, PostgreSQL and SQLite.