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.
$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.