Simplest way to increment a date in PHP?

Simplest way to increment a date in PHP?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Incrementing Dates in PHP: Beyond strtotime

When working with date strings like "2007-02-28", the immediate instinct is often to treat the date as a timestamp and perform arithmetic on it. Using strtotime() followed by adding seconds (24*60*60) and formatting back with date() works, but it introduces unnecessary cognitive load. You are converting a human-readable format into a Unix timestamp, performing math in a unit that doesn't match the input, and converting back. This round-trip is prone to timezone ambiguities and feels clunky when you simply want to add one day.

A cleaner approach leverages PHP's native string manipulation capabilities or specific date functions designed for interval arithmetic. The most direct method for adding exactly one day to a YYYY-MM-DD string involves using strtotime() with a relative unit modifier, rather than calculating seconds manually. You can pass the original string to strtotime(), which parses it into an internal timestamp, and then specify the increment directly in the format string itself.

Here is how you achieve that increment cleanly:

$input = '2007-02-28';
$nextDay = date('Y-m-d', strtotime($input . '+1 day'));
// Result: "2007-03-01"

This pattern is significantly more readable than calculating 24*60*60. It explicitly communicates the intent: "take this date and move forward one day." While strtotime() still relies on C's time_t internally, wrapping the logic inside the format string keeps the code concise. If you are dealing with a fixed interval like exactly one month or one year, however, strtotime() becomes unreliable due to varying month lengths and leap years. For those scenarios, DateTime objects provide robustness that simple string parsing cannot match.

If your application requires precision regarding timezones or needs to handle edge cases like month-end rollovers (e.g., January 31st to February 28th/29th), relying solely on date() and strtotime() can lead to subtle bugs. In those contexts, creating a DateTime object is the standard best practice:

$date = new DateTime('2007-02-28');
$date->modify('+1 day');
echo $date->format('Y-m-d');

The modify() method handles the calendar logic internally, ensuring that February 28th correctly increments to March 1st without you needing to worry about how many days are in a specific month. This approach also makes it trivial to format the output in whatever locale or timezone is appropriate for your application context.

For developers using the Laravel framework, there is an even higher-level abstraction available. The Carbon library (via laravel/carbon) extends PHP's DateTime class with fluent methods that make date manipulation extremely expressive. Instead of chaining methods like modify() and then format(), Carbon allows you to use a more natural syntax:

use Carbon\Carbon;

$date = Carbon::parse('2007-02-28');
$nextDay = $date->addDay();
echo $nextDay->toDateString(); // "2007-03-01"

This syntax is particularly useful when readability is a priority, as it reads almost like natural language. If your project already uses Laravel, integrating Carbon is often the default choice for complex date operations. For simpler scripts or non-Laravel projects, sticking to DateTime or the +N day trick with strtotime() strikes the right balance between simplicity and reliability.

Ultimately, the goal is to avoid manual arithmetic on timestamps unless absolutely necessary. By delegating the calendar rules to PHP's built-in date functions or libraries like Carbon, you ensure your code remains maintainable and less prone to timezone-related headaches.

Our network