Today now in this post i will show you How to Get Difference of Time in Minutes in Laravel? Sometimes we may need to calculate minutes difference between the two dates in any version laravel 5, laravel 6, laravel 7 and laravel 8 Application. But In Laravel provide the Carbon class. It Help of Carbon class we can easily simply calculate the minutes difference between the two dates. We can simply customize the code also.
Now in the following example we can see, we have a two dates, first one is $to variable and second one is $from variable. Now using Carbon class diffInDays function by using we can get difference between the two dates.
So, let’s see the bellow example, it is very pretty and simple:
$to = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', '2021-02-01 13:30:24'); $from = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', '2021-02-01 13:35:14'); $diff_in_minutes = $to->diffInMinutes($from); print_r($diff_in_minutes);
Thanks for read. I hope it help you. For more you can follow us on facebook