Table of contents

Get The Difference Between Two Date and Time in Minutes with Laravel

If you have a task that should calculate the difference between two DateTime in minutes with Laravel then this could help you. In this case, we are going to use the Carbon package to calculate the difference in minutes. Carbon is already in Laravel core so nothing to worry about during the installation.

 

So to do this we need to define a start and end DateTime so that easier for you to understand and follow.

 

$start = Carbon::parse("2022-08-19 16:21:03");
$end = Carbon::parse("2022-08-19 16:28:03");

$total = $end->diffInMinutes($start);

echo $total;//Output: 7

 

That's pretty much it. I hope this simple solution could help you :)