Reputation: 99
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
Upvotes: 0
Views: 405
Reputation: 39470
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
Upvotes: 4