I have some events stored in a database using doctrine and Symfony2, and those events have a two datetime parameters, start and end of the event. I need to know if those events are active during a certain month, but i cant find a way. I tried with :
$now = new \Datetime('now');
$qb = $this->createQueryBuilder('e');
$qb->where('e.start <= :now AND e.end >= :now')
->setParameter('now', $now);
return $qb->getQuery()
->getArrayResult();
but it limits to the day, and not to the month. Is there a way to check it ? Thanks a lot !
You can use the following code
$monthStart = new DateTime(date('Y-m-01') . " 00:00:00");
$monthEnd = new DateTime(date('Y-m-t'). " 23:59:59");
$qb = $this->createQueryBuilder('e');
$qb
->where('e.start <= :end AND e.end >= :start')
->setParameter('start', $monthStart)
->setParameter('end', $monthEnd);
return $qb->getQuery()
->getArrayResult();