Skip to content
Advertisement

How to use ‘interval’ in Doctrine2 Query Builder

In my Symfony2 repository, I’d like to get objects from a schedule table, that have started, but not finished yet. The interval, within the objects should be encountered as ‘not finished’, should be passed as a variable.

Using plain SQL, it works like this:

JavaScript

Can I achieve the same with DQL / Query Builder?

This is what I have so far:

JavaScript

But this returns the following error:

JavaScript

I found that ‘interval’ is not supported by Doctrine2 / DQL, which is also mentioned here.

Any suggestions on how to accomplish this with Doctrine2’s Query Builder or DQL (and passing the interval as variable)?

Advertisement

Answer

As far as I know, Interval is not ported in Doctrine. The workaround I found is to work directly on the DateTime I pass as a param (here, I’d like to use interval of 2 days, passed through Datetime):

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement