Home > Mobile >  PHP Carbon does not calculate the time difference
PHP Carbon does not calculate the time difference

Time:03-08

I need to get the time difference.But carbon does not calculate.

date1  2022-03-30 00:00:00   
date2  2022-03-30 21:00:00  

$interval = $date1->diffInSeconds($date2);            -> OUTPUT: 0
$interval2 = $date1->diffAsCarbonInterval($date2);    -> OUTPUT: 

CodePudding user response:

You should parse all the data with Carbon to convert it to Carbon instance, then you can get the difference

 $diffInSeconds = Carbon\Carbon::parse('2022-03-30 00:00:00')->diffInSeconds(Carbon\Carbon::parse('2022-03-30 21:00:00'));
  • Related