Laravel Carbon Add Days to Date Example Tutorial

Aug 05, 2021 . Admin



Hi All,

In this Tutorial i will explain you how to add days to date in laravel using carbon in laravel so it can easy to use in laravel app.

Whenever,if you require to add day or more days in date then you can use carbon in laravel. carbon provide inbuilt function addDay()

and addDays() method to add days on carbon date object. so let's see some examples to adding day and days and sub day and days from date.

Here, I will give you full example for how to add days to date in laravel using carbon. so follow my example code and you can use your laravel application copy that code.

Solution
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Carbon\Carbon;

class HomeController extends Controller
{
    /**
     * laravel carbon add days to date..
     *
     * @return string
    */
    public function index(Request $request)
    {
        $currentDateTime = Carbon::now();
        $newDateTime = Carbon::now()->addDay();

        // echo "<pre />";
        print_r($currentDateTime);
        print_r($newDateTime);
    }

}
Output
Carbon\Carbon Object

(
    [date] => 2021-08-05 05:02:54.665203

    [timezone_type] => 3

    [timezone] => UTC
)

Carbon\Carbon Object

(
    [date] => 2021-08-06 05:02:54.665206

    [timezone_type] => 3

    [timezone] => UTC
)

I Hope It Will Help You..

#Laravel 8 #Laravel