How to Get Difference Between Two Dates in Laravel Carbon

Hello artisan,

In this quick tutorial, I will show you laravel carbon count days between dates. It is going to be a simple example of laravel carbon get difference between two dates in days. I will help you to give an example of calculate days between two dates in laravel using carbon. So let us discuss the carbon difference between two dates in days.

We can use this example with laravel 6, laravel 7, laravel 8 and laravel 9 version. In the following example you can see, laravel carbon get number of days between two dates. So let's see the example code:

namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use Carbon\Carbon;
  
class DemoController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $startDate = Carbon::parse("2022-10-28");
        $endDate = Carbon::parse("2022-11-21");
  
        $diffInDays = $startDate->diffInDays($endDate);
   
        dd($diffInDays);
    }
}

 

Read also: Laravel Carbon Parse Date Format Code Example

 

Hope it can help you.

 

author-image
Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js