How to get days difference between two dates in Laravel?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now i will show you how to get days difference between two dates in laravel. When we need to get difference between two dates in date in laravel application then we can get easily do it by using Carbon. In Laravel by default provide Carbon class. By using Carbon class we can calculate difference between two dates in days.

Now in the following example we can see that. We have two dates, first one is $to variable and second one is in $from variable. By using Carbon class diffInDays function we can get difference between two dates.So now I hope you will find your best solution.

Example:

$to = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', '2015-5-5 3:30:34');
$from = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', '2015-5-6 9:30:34');
$diff_in_days = $to->diffInDays($from);
print_r($diff_in_days); // Output: 1

Read Also : How to get last 7 days record in laravel?

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

About Shahriar Sagor

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 Shahriar Sagor →