How to Get Difference of Time in Minutes in Laravel?

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:

Example:
$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); 

Read Also: How to implement infinite ajax scroll pagination in Laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook

Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.