17

I am trying to use the DATE_ADD function from doctrine2 but I am having trouble get it right.

I am using like this in DQL:

->andWhere('p.created_at <= DATE_ADD(CURRENT_DATE(),4, day)')

but I am getting syntax error:

[Syntax Error] line 0, col 215: Error: Expected'.' or '(', got 'day'

I tried different implementations but I allways get some kind of syntax errror.

I have checked DoctrineExtensions which contain this function, but I shouldnt need it because the function is already included in doctrine.

j0k
  • 22,600
  • 28
  • 79
  • 90
brpaz
  • 3,618
  • 9
  • 48
  • 75

1 Answers1

41

You have a typo, you have to quotes 'day'

->andWhere("p.created_at <= DATE_ADD(CURRENT_DATE(),4, 'day')")

An example here.

Pierrickouw
  • 4,644
  • 1
  • 30
  • 29
  • 6
    If you replace all `'` with `"` and vice versa (like: `>andWhere('p.created_at <= DATE_ADD(CURRENT_DATE(),4, "day")')` )it would not work. – pmaruszczyk Jun 23 '16 at 09:41