DEV Community

loading...

Carbon Add Days To Date In Laravel

websolutionstuff profile image Websolutionstuff Originally published at websolutionstuff.com ・1 min read

Today in this post i will show you Carbon Add Days To Date In Laravel. Carbon provides addDay() and addDays() method to add days on carbon date object.

So we will see laravel carbon add days or how to add days in date in laravel 8.

laravel add days to date provides you to add extra date using carbon

addDay() Example

<?php

namespace App\Http\Controllers;

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

class DateController extends Controller
{
    public function index()
    {
        $currentDateTime = Carbon::now();
        $newDateTime = Carbon::now()->addDay();

        print_r($currentDateTime);
        print_r($newDateTime);
    }
}
Enter fullscreen mode Exit fullscreen mode

Output :

Carbon\Carbon Object
(
    [date] => 2020-12-02 08:51:57.696013

    [timezone_type] => 2

    [timezone] => GMT
)

Carbon\Carbon Object
(
    [date] => 2020-12-03 08:51:57.696023

    [timezone_type] => 2

    [timezone] => GMT
)
Enter fullscreen mode Exit fullscreen mode

addDays() Example

<?php

namespace App\Http\Controllers;

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

class DateController extends Controller
{
    public function index()
    {
        $currentDateTime = Carbon::now();
        $newDateTime = Carbon::now()->addDays(3);

        print_r($currentDateTime);
        print_r($newDateTime);
    }
}
Enter fullscreen mode Exit fullscreen mode

Output :

Carbon\Carbon Object
(
    [date] => 2020-12-02 08:55:58.896013

    [timezone_type] => 2

    [timezone] => GMT
)

Carbon\Carbon Object
(
    [date] => 2020-12-05 08:55:59.796023

    [timezone_type] => 2

    [timezone] => GMT
) 
Enter fullscreen mode Exit fullscreen mode

Read Also : Laravel 8 Socialite Login with Google Account


Read Also : Stripe Payment Gateway Integration Example In Laravel 8

Thanks for the reading...!!

Discussion (0)

pic
Editor guide