1

I need to make a query to get the row where the active field is true or the current date is between two stored dates Itring with

 $qb->andWhere('p.active = true')')
                ->orWhere($qb->expr()->andX(
                    $qb->expr()->lt('p.activationDate', 'now()'),
                    $qb->expr()->eq('p.deactivationDate', 'now()')
                ))
            ->setMaxResults(1);

But I get :

[Syntax Error] line 0, col 145: Error: Expected known function, got 'now'
fg_st
  • 109
  • 5
  • 1
    Does this answer your question? [How can I use now() in Doctrine 2 DQL?](https://stackoverflow.com/questions/8347872/how-can-i-use-now-in-doctrine-2-dql) – Trece Sep 09 '22 at 07:41

1 Answers1

0

the were can be like this:

->andWhere("CURRENT_TIMESTAMP() BETWEEN p.activationDate and p.deactivationDate")

like this:

$repo = $this->em->getRepository(YourRepo::class);
$result = $repo->createQueryBuilder("p")
    ->andWhere("CURRENT_TIMESTAMP() BETWEEN p.activationDate and p.deactivationDate")
    ->getQuery()
    ->getResult();
FF MM
  • 138
  • 9