Hello to all, welcome to therichpost.com. In this post, I will tell you, How to get date difference in hours and days with laravel carbon? Like I always say that laravel is the best Mvc php framework.
Carbon class is inherited from the PHP DateTime class.
Here is working and tested code and you can add this code in laravel controller file:
public function custom_date_diff($previous_date){ $fdate = "2018-06-03"; $tdate = Carbon::now()->toDateTimeString(); $datetime1 = new \DateTime($fdate); $datetime2 = new \DateTime($tdate); $interval = $datetime1->diff($datetime2); $hours = $interval->h;//now do whatever you like with $hours $days = $interval->format('%a');//now do whatever you like with $days return $hours; }
If you have any query related to this post then please do comment below and I will come with more laravel posts.
Recent Comments