How to get days difference between two dates in laravel?By Hardik Savani | January 29, 2016 | | 5646 Viewer | Category : Laravel
Share this post:
Whenever you need to get difference between two dates in date in laravel 5 then you can get easily using Carbon. Laravel by default provide Carbon class. Carbon class throught you can calculate difference between two dates in days.
In Following example you can see, we have a two dates, first $to variable and second one $from variable. Carbon class diffInDays function using you can get difference between two dates. I hope you will find your 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
- HTML/FORM not found in Laravel 5?
- Laravel 5 - Barcode generator example using milon/barcode package
- PHP Codeigniter - Ajax Infinite Scroll Pagination Example
- Laravel 5 - line chart example code using google charts API
- AngularJS - How to call function on page load example with demo?
- Laravel 5.4 New Feature - Add new Components & Slots in Blade Template
- Laravel 5 - How to get difference of time in minutes?
- How to create and check custom header with middleware for REST API in Laravel 5 ?