laravel 8 date difference in days 1

laravel 8 date difference in days

        $last_date = "2018-01-10 00:00:00";
        $current_date = Carbon::now()->toDateTimeString();

          //NUMBER DAYS BETWEEN TWO DATES CALCULATOR
          $start_date = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $last_date);
          $end_date = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $current_date);
          $different_days = $start_date->diffInDays($end_date);

Here is what the above code is Doing:
1. We’re creating a variable called $last_date and setting it to a date in the past.
2. We’re creating a variable called $current_date and setting it to the current date.
3. We’re creating a variable called $start_date and setting it to the $last_date variable.
4. We’re creating a variable called $end_date and setting it to the $current_date variable.
5. We’re creating a variable called $different_days and setting it to the difference in days between the $start_date and $end_date variables.

Similar Posts