phpsymfonydoctrine-orm

Getting error while using interval in doctrine


When I use below query (Doctrine 2), I was getting error, and can't use INTERVAL in query,

$qb->andWhere("(pv.appointment_date + INTERVAL 48 HOUR) >= UTC_TIMESTAMP()");

Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '48'"


Solution

  • If you want to use INTERVAL (in Doctrine 2, DQL) on mysql comumn field, You can use as below,

    $qb->andWhere("DATE_ADD(pv.appointmentDate,48,'hour') >= UTC_TIMESTAMP()");
    

    It will print SQL as below,

    ...... DATE_ADD(p0_.appointmentDate, INTERVAL 48 HOUR) >= UTC_TIMESTAMP() .....