0

i'm trying to do a query that find entity of this year .

i try this but don't work

$em = $this->getDoctrine()->getManager(); $query = $em->createQuery( 'SELECT p FROM AppBundle:Analisi p WHERE p.dataCreazione > :current_year ORDER BY p.dataCreazione ASC' )->setParameter('current_year', date("Y").'01-01'); $analisi = $query->getResult(); 

it return analisi in database. It don't work but i don't understand why

1
  • Can you show your error? Commented Sep 2, 2017 at 17:53

1 Answer 1

4

try with one more minus symbol as: date("Y").'-01-01')

 ->setParameter('current_year', date("Y").'-01-01'); 

more readable way could be:

 $date= date('Y-m-d', strtotime('first day of january this year')); $query = $em->createQuery( 'SELECT p FROM AppBundle:Analisi p WHERE p.dataCreazione > :current_year ORDER BY p.dataCreazione ASC' )->setParameter('current_year', $date); 

Hope this help

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

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.