1

I want to delete all the entries from my database where the ending date is reached

 $em = $this->getEntityManager(); $qb = $em->createQueryBuilder('f'); $qb->delete('AcmeMyBundle:FlowerEntity'); $qb->where($qb->expr()->lte('f.endingDate', ':now')); $qb->setParameter('now', new \DateTime('now')); return $qb->getQuery()->getResult(); 

I get the error

[Syntax Error] line 0, col 57: Error: Expected end of string, got 'f' 

I tried many ways but unfortunately without much success.. Any clues ? Thanks !


SOLUTION based on NHG answer

 $em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $qb->delete('AcmeMyBundle:FlowerEntity', 'f'); $qb->where($qb->expr()->lte('f.endingDate', ':now')); $qb->setParameter('now', new \DateTime('now')); return $qb->getQuery()->getResult(); 

2 Answers 2

4

I dont't know what is your definition of endingDate field, but you could try to convert a DateTime object to string:

$date = new \DateTime('now'); // query $qb->setParameter('now', $date->format('Y-m-d h:i:s')); 

EDIT:

So problem is with f argument in $em->createQueryBuilder('f'). Try:

$em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $qb->delete('AcmeMyBundle:Flower', 'f'); // further code 

Doc. Additionaly I used Flower instead of FlowerEntity.

Sign up to request clarification or add additional context in comments.

1 Comment

endingDate is a dateTime too , how can i change that one into string? i've tried f.endingDate->format( .. ) in the query but it throw expected parameter 1 to be object boolean given (it looked so dirty i hesitated to try this lol )
0

you can compare by Datetime like this:

$qb->where('f.endingDate <= :minDatetime'); $qb->setParameter('minDatetime', $minDatetime); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.