Get a list between two dates

0

I have created a restful api that obtains a list of coordinates that are stored in a database that follows the following format: / devices / 1 / gpses / 0, where the first number is the identifier of the device we want to see and the second is since when we want to obtain data, in Unix Timestamp format. For a specific date you do not have any problem. My question is whether I want to obtain the data between two specific dates. The beginning of the code I have more or less calro:

$fechaInicial = strtotime($fechaInicial);
$fechaFinal = strtotime($fechaFinal);
$posicionesIntermedia =  $this->obtenerUnSeguimiento($dispositivoId, $fechaInicial);

And I know that the next thing would be to do a path of $posicionesIntermedias discarding all those data that are greater than $fechaFinal . But I do not know how to focus the foreach.

I forgot to say that the answer of the api is a json composed of the data fecha , dispositivo_id , latitud and longitud

Any help?

EDIT: I add the method code to get aSegment ()

protected function obtenerUnSeguimiento($id, $fecha)
{
    $respuesta = $this->realizarPeticion('GET', "https://localhost/dispositivos/{$id}/gpses/{$fecha}");
    $datos = json_decode($respuesta);
    $posiciones = $datos->data;
    return $posiciones;
}
    
asked by miguelex 06.06.2018 в 12:20
source

2 answers

0

I have already fixed it ... in case it helps, what I have done is the following:

foreach ($posicionesIntermedia as $pos)
{
    if ($pos->fecha < $fechaFinal)
    {
        array_push($posiciones, $pos);
    }
}

Thanks for the help.

    
answered by 07.06.2018 / 09:03
source
1

Since you do not indicate what the function does to obtain a Follow-up (), a possible solution would be to raise the for in this way:

$fechaInicial = strtotime($fechaInicial);
$fechaFinal = strtotime($fechaFinal);

for($cont = $fechaInicial; $cont < $fechaFinal; $cont++) {

    $temp =  $this->obtenerUnSeguimiento($dispositivoId, $cont);

    if(!is_null($temp))
        $posicionesIntermedia[$cont] = $temp;
}

Here you would have a series of optimization problems. Maybe you should check the function getA follow-up () and see if you can pass the start and end dates, and make a query with them.

    
answered by 06.06.2018 в 13:37