Laravel
Hours difference between two dates in Laravel?
In this blog, we will see how to get hours difference between two dates in Laravel.Whenever you need to get the difference between two dates in hours in laravel 5 then you can get easily using Carbon. Laravel by default provides the Carbon class. Carbon class through you can calculate the difference between two dates in hours.
In the Following example you can see, we have two dates, the first $to variable and second one $from the variable. Carbon class diffInhours function using you can get the difference between two dates. I hope you will find your 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-5 9:30:34');
$diff_in_hours = $to->diffInHours($from);
print_r($diff_in_hours);// Output: 6
You can also read: Get current month and year data in laravel
2 Comments