In this post, I will let you know how to get difference in time from given dates in Laravel 5.
This is required to calculate minutes left from scheduled time.
For example, If there is functionality to schedule appointment through your website and you need to send the push notification to user that you have scheduled the appointment at given time and there are only {time} left from your scheduled appointment.
There, you will need this functionality to calculate hour, minutes and seconds between two dates.
Ok, let's have a example :
Example
- $to = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', '2017-5-6 3:30:10');
- $from = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', '2017-5-6 3:35:35');
- $diff_in_seconds = $to->diffInSeconds($from);
- print_r($diff_in_seconds); // Output: 325
- $diff_in_minutes = $to->diffInMinutes($from);
- print_r($diff_in_minutes); // Output: 5
- $diff_in_hours = $to->diffInHours($from);
- print_r($diff_in_hours); // Output: 0