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

Asked

Viewed 326 times

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"

1 answer

1


The date has to be the highest, for the data to take the negative difference, 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);

Upshot:

-5

Reference:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.