I am working on a repo to find all booking done in a reservation during a period. I have a check-in date and a number of nights they stay.
/*
* @return array
*/
public function findAllByHotelIdAndDate(int $id, \DateTime $date)
{
$qb = $this->createQueryBuilder('re')
->leftJoin(Room::class, 'ro')
->leftJoin(Hotel::class, 'h')
->where('h.id =:idHotel')
->andWhere('re.checkIn >= :date')
->andWhere("DATE_ADD(re.checkIn, re.nights, 'day') <= :date")
->setParameters(['date' => $date, 'idHotel' => $id])
;
$query = $qb->getQuery();
return $query->execute();
}
My issue is on the use of DATE_ADD
.
Is my syntax correct?