Carbon Add Days To Date In Laravel

Websolutionstuff
1 min readApr 12, 2021

--

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

<?phpnamespace 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);
}
}

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
)

addDays() Example

<?phpnamespace 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);
}
}

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
)

--

--

Websolutionstuff
Websolutionstuff

Written by Websolutionstuff

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API. Visit Website: http://websolutionstuff.com/

No responses yet