Carbon diffInDays does not bring the negative value between two dates (positive only) [closed]

3
$datNow = Carbon::parse('2018-10-23 18:40:11.000000');
$datSuspensao = Carbon::parse('2018-10-18 00:00:00.390176');
$diasRestantes  = $datSuspensao->diffInDays($datNow);

dd($diasRestantes);
//Imprime 5 (Na verdade queria imprimir -5)

$datNow = Carbon::parse('2018-10-23 18:40:11.000000');
$datSuspensao = Carbon::parse('2018-10-18 00:00:00.390176');
$diasRestantes  = $datSuspensao->diffInDays($datNow, false); //Coloquei false como segundo parâmetro e não deu certo

dd($diasRestantes);
//Continua imprimindo 5

$datNow = Carbon::parse('2018-10-23 18:40:11.000000');
$datSuspensao = Carbon::parse('2018-10-18 00:00:00.390176');
$diasRestantes  = $datSuspensao->diffForHumans($datNow);

dd($diasRestantes);
//Imprime "5 dias atrás"
    
asked by anonymous 23.10.2018 / 14:22

1 answer

1

The date has to be the greater, so that the data takes the negative difference, for example:

Code:

$datNow = Carbon::parse('2018-10-23 18:40:11.000000');
$datSuspensao = Carbon::parse('2018-10-18 00:00:00.390176');

//A data maior faz a diferença na data menor
$diasRestantes = $datNow->diffInDays($datSuspensao, false);

Result:

-5

Reference:

23.10.2018 / 14:31