How to Get difference between two dates in days using carbon in laravel

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Hello Dev’s
Today now in this example, I will teach you How to get difference between two dates in days by using carbon in laravel 8 application. So we need to get difference between two dates in count to days by using carbon in laravel application. Now we can do it simply by use to diffInDays() method in laravel application.

Now in following example we can see, we have two dates, first one is $start_date variable and second one is in $end_date variable. Now Carbon class diffInDays function using we can get difference between two dates on variables. So I hope you get find your best solution.

Example 1 :

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(Request $request)
{
  $start_date = \Carbon\Carbon::createFromFormat('d-m-Y', '1-5-2015');
  $end_date = \Carbon\Carbon::createFromFormat('d-m-Y', '10-5-2015');
  $different_days = $start_date->diffInDays($end_date);

  dd($different_days);
}

Read Also : How to add 1 day to the date column in MySQL?

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

About code chef

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.

View all posts by code chef →