How to get hours difference between two dates in laravel?By Hardik Savani | February 13, 2016 | | 3292 Viewer | Category : Laravel
Share this post:
Whenever you need to get difference between two dates in hours 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 hours.
In Following example you can see, we have a two dates, first $to variable and second one $from variable. Carbon class diffInhours 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-5 9:30:34');
$diff_in_hours = $to->diffInHours($from);
print_r($diff_in_hours);// Output: 6
- Laravel - How to get current URL in controller or view?
- How to solve "Cannot find module 'bplist-parser'" ?
- Bootstrap - Show/Hide(toggle) Password input field using bootstrap-show-password.js Plugin
- Laravel 5 Ajax CRUD with Pagination example and demo from scratch
- Bootstrap - Input multiple tags example using Tag Manager Jquery Plugin
- PHP - How to convert HTML file to PDF using Dompdf library?
- Ckeditor required field validation example in Jquery
- Laravel 5 create Custom Validation Rule example.