Laravel Carbon Count Days Between Two Dates Example

By Hardik Savani April 16, 2024 Category : Laravel

Hello Friends,

In this quick guide, we will teach you laravel carbon count days between dates. It's a simple example of laravel carbon get difference between two dates in days. we will help you to give an example of calculate days between two dates in laravel. let’s discuss about carbon difference between two dates in days.

you can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.

In the following example you can see, we have two dates, the first $startDate variable and the second one $endDate variable. Carbon class diffInDays() function using you can get the difference between two dates in days. I hope you will find your solution.

Example:

<?php

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);

}

}

Output

24

I hope it can help you...

Tags :
Shares