0

I have this sql query:

SELECT * from gift WHERE NOW() >= `validbegin` AND NOW() <= `validend` ORDER BY `points`n ASC

I need to transform it to a Symfony 2 query to fetch the data to an object call Gift. So far I have this:

    $query = $giftRepository->createQueryBuilder('p')
        ->where('NOW() >= validbegin AND NOW() <= p.validend')
        ->orderBy('p.points', 'ASC')
        ->getQuery();
    $gifts = $query->getResult();

But that gave me:

[Syntax Error] line 0, col 53: Error: Expected known function, got 'NOW'

Any idea?

ps. Also tried p.NOW()

1
  • what kind of field it is , datetime ? Commented Jan 24, 2013 at 20:48

1 Answer 1

1

Try this :

$query = $giftRepository->createQueryBuilder('p')
    ->where(':now >= validbegin AND :now <= p.validend')
    ->setParameter('now', new \DateTime())
    ->orderBy('p.points', 'ASC')
    ->getQuery();
$gifts = $query->getResult();

You generate the field from php, then doctrine will automatically convert it to a mysql timestamp

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.