The question is how is it possible to get difference in days from before to today and knowing this difference is happened in the past?
Asked
Active
Viewed 186 times
1 Answers
1
Yes its possible to get difference in days from before to today, all you need is the dates. for the example this is some check in and check out date diff.
// Params in date
public static function getDateDifference($check_in, $check_out)
{
$check_in = strtotime($check_in);
$check_out = strtotime($check_out);
$date_difference = $check_out - $check_in;
$date_difference = round($date_difference / (60 * 60 * 24));
return $date_difference;
}

Wailan Tirajoh
- 481
- 5
- 17
-
Is it your custom static function or laravel's carbon already have it? – Mahdi Rashidi Apr 24 '21 at 11:55
-
Its my custom static function – Wailan Tirajoh Apr 24 '21 at 11:57
-
How can I use it? – Mahdi Rashidi Apr 24 '21 at 11:57
-
You can create your Helper.php at app/Helpers/Helpers.php – Wailan Tirajoh Apr 24 '21 at 11:57
-
In diffInDay we use the syntax like this now()->DiffInDays($date->toString())? So how is it possible to use it? – Mahdi Rashidi Apr 24 '21 at 11:58
-
I'm not good at static using function give me some example, please. – Mahdi Rashidi Apr 24 '21 at 12:03
-
Here the keyword "Laravel helper | How to create helper | Create custom helper function | Laravel 8 | Learning Points" Find it at youtube, video by Learning Points. But he didn't make it as Class Helpers so you have to custom some of his code. just PM me if you stuck somewhere – Wailan Tirajoh Apr 24 '21 at 12:06
-
Thank you for the answer. I will give a try but by now I accept the answer because it makes sense – Mahdi Rashidi Apr 24 '21 at 12:16