Web Development. Client Satisfaction. Web Consultancy. Professional. UX. Fast. Responsive Design. Dynamic. Interactive. Innovative. Ecommerce. Wordpress plugins. Prestashop modules. You name it.

How To Use DAY, MONTH, YEAR Functions In Doctrine Symfony

How To Use DAY, MONTH, YEAR Functions In Doctrine Symfony

If you want to use these functions in symfony dotrine you need to know that these functions does not come when you install doctrine. So you will have to install an extension for doctrine in order to know what should do when you insert the code in your repository. To install the extension go to this link. You can install it using composer you will find on github all the required steps you need in order to install it correctly. Then we have to do some settings in symfony to make this work. So open your symfony project using a ftp client and go to: config -> packages -> doctrine.yaml.

In this file you should check if already have orm parameter if not you will have to add the following code to make it work.

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

Add the above code and then function day month year and all functions which are in guthub should work without any problem. 

How to use day in repository custom function

And a little below I will show you how to use DAY() function in repository function:

->select('DAY(e.dateCreated))

In this way doctrine when you will get the data from database will change the date format and will give you back only the day. Then you can use any function you need on day var, functions such as: groupBy or other functions like that one.

Leave a Reply

avatar
  Subscribe  
Notify of