It happens that I have a table where I keep records of things that are going to be done with a format: task, start date, end date
Example: Pruning the lawn, 2018-02-20, 2018-02-25
What I need is that you can not register in the BD tasks that are on that date or go through it.
The first case is already solved that is to report a task with a date greater than or equal to the start date and the end date is less than or equal to the record of the BD that is being evaluated:
Following the previous example: Prune the lawn, 2018-02-20, 2018-02-25
If I want to register a task, clean the pool with start date 2018-02-21, do not let it be done.
The detail is when I register a task like this:
Change the bulbs, 2018-02-15, 2018-02-30
I have not been able to identify how to detect that there are dates within this range.
The fuck I'm using is this:
//datos enviados desde el form
$start = date('Y-m-d', strtotime($start));
$end = date('Y-m-d', strtotime($end));
//obtengo las tareas registradas a futuro en la BD
$actualNovelties = $em->getRepository('RocketSellerTwoPickBundle:Novelty')->getRegisterVacationsNoveltiesByUser($payroll);
// creo un flag para validar si existen registros en ese rango
$flagSame = 0;
//valido si existen datos en la variable
if($actualNovelties != null){
//recorro cada una de las tareas
foreach ($actualNovelties as $actualNovelties){
//convierto a timestamp las fechas de los registros de la BD
$dateBegin =strtotime($actualNovelties->getDateStart()->format('Y-m-d'));
$dateEnd = strtotime($actualNovelties->getDateEnd()->format('Y-m-d'));
//valido si la fecha de inicio enviada desde el form se cruza con las fechas de la BD
if ((strtotime($start) >= $dateBegin) && (strtotime($start) <= $dateEnd))
{
// si cumple la condición incrementa el flag
$flagSame++;
}
//valido si la fecha fin enviada desde el form se cruza con las fechas de la BD
if ((strtotime($end) >= $dateBegin) && (strtotime($end) <= $dateEnd))
{
// si cumple la condición incrementa el flag
$flagSame++;
}
}
}