Table of contents
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 :)
Read next