Search code examples
phplaravellaravel-5

Add days to date in Laravel


I am beginner in Laravel. I use in my project Laravel 5.8.

I have this code:

$userPromotionDays = $user->premiumDate; // 2019.08.28
$daysToAdd = 5

How can I add $userPromotionDays to $daysToAdd (in Laravel/Carbon)?


Solution

  • You can create date with custom format and then add days to it using carbon.

    $date =2024-08-08;
    $daysToAdd = 5;
    $date = $date->addDays($daysToAdd);
    dd($date);
    

    You can see details documentation here.