Add days to date in Laravel

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Adding Days to Dates in Laravel Using Carbon

As a beginner in Laravel, you may come across situations where you need to manipulate dates in your applications. One such common task is adding days to a given date. In this blog post, we will provide a thorough answer and relevant code examples for effectively handling date arithmetic using the Laravel Carbon package.

Understanding Carbon

Carbon is a PHP library that simplifies working with dates and time in your applications. It comes as part of the Laravel framework and offers an expressive API for manipulating dates and times. By default, PHP provides basic date functions but lacks comprehensive support for time zones and other advanced features. Carbon helps you overcome this limitation by providing a powerful toolset to work with dates and times in your code.

Adding Days to Dates

To add days to a given date, you can use the addDays() method provided by Laravel's Carbon package. In your example, you have two variables: $userPromotionDays and $daysToAdd. To accomplish the desired task, follow these steps: 1. Create an instance of the Carbon date object using the given date from $userPromotionDays with the Carbon::parse() method. 2. Add the specified number of days to this date, which is already in Carbon format, using addDays(). 3. Output the result for verification. Here's an example code snippet:
$userPromotionDays = Carbon::parse($user->premiumDate); // 2019-08-28
$daysToAdd = 5

$newPromotionDate = $userPromotionDays->addDays($daysToAdd);

// Output the new date with formatted output
echo $newPromotionDate->format('Y-m-d');
This example adds 5 days to the given date and outputs it in a formatted way. The result would be: "2019-09-02".

Further Exploration

While adding days is one of the most common arithmetic operations with dates, Carbon offers many other methods for manipulating dates and times. Some of these include: 1. Adding or subtracting years, months, weeks, hours, minutes, and seconds. 2. Manipulating time zones and working with daylight saving time settings. 3. Formatting dates in various localized formats. 4. Calculating the difference between two dates or times. 5. Creating recurring events using cron expressions. These features make Laravel's Carbon package an essential tool for any PHP developer who needs to effectively handle date and time-related tasks in their applications.

Conclusion

In this blog post, we have explored how to add days to a given date using the Laravel framework and its associated Carbon package. We presented code examples, best practices, and further exploration tips for developers who want to master date manipulation in their applications. Always remember that maintaining a high-quality and well-structured codebase is crucial for future maintenance and scalability of your projects.