PHP - add 1 day to date format mm-dd-yyyy

PHP - add 1 day to date format mm-dd-yyyy

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

Stefan Bogdanescu

Founder & Senior Architect

Adding Days to Date Strings in PHP Without Losing Precision

The behavior you are seeing, where echo returns 01-01-1970, is a classic symptom of how strtotime() handles string formats differently than human intuition expects. When you pass "04-15-2013" directly to strtotime(), the function attempts to parse it. While it might successfully interpret month-day-year formats in many contexts, the underlying issue often stems from the ambiguity of non-standard formats or how the resulting timestamp interacts with daylight saving time adjustments if not handled carefully. However, in your specific case, the most likely culprit is that strtotime() on its own can sometimes be finicky with strict m-d-Y patterns without additional context, or it might be interpreting the string as invalid depending on the PHP version and locale settings, defaulting to a timestamp of 0 (January 1, 1970).

The core problem with relying solely on strtotime() for arithmetic operations is that it returns a Unix timestamp. While timestamps are excellent for calculating differences or sorting, they abstract away the human-readable format until you use date() to format them back out. If your input string fails to parse correctly into a valid timestamp initially, adding one day to an invalid timestamp (0) will simply result in an invalid timestamp (86400), which still formats as 01-01-1970.

To solve this robustly, you must ensure the initial string is converted to a reliable object or a valid integer timestamp before performing arithmetic. The modern standard in PHP 5.5+ and especially PHP 7+ is to use the DateTime class. This class handles parsing, timezone offsets, and arithmetic operations with far fewer edge cases than the procedural date() functions.

Here is how you should approach adding a day to a date string received via POST:

// Assume $date comes from $_POST in format m-d-Y
$inputDate = $_POST['date_field']; 

// Create a DateTime object directly from the string
$startDate = new DateTime($inputDate);

// Add one day using the built-in interval modifier
$startDate->modify('+1 day');

// Output in the desired m-d-Y format
echo $startDate->format('m-d-Y');

This approach is superior because DateTime parses the string "04-15-2013" immediately upon instantiation. If the parser fails (e.g., if the month doesn't exist), it throws an exception rather than silently returning a default timestamp, allowing you to catch errors early. Once the object is created, calling modify('+1 day') adds exactly 24 hours to that specific point in time, accounting for leap seconds and daylight saving time transitions automatically.

If you prefer sticking to the procedural functions without objects, you must wrap strtotime() with error checking or ensure the format is strictly validated first. You can also use DateTimeImmutable if you need to preserve the original date string state while creating a new modified version, preventing side effects on your original variable.

$originalDate = $_POST['date_field'];
$modifiedDate = new DateTimeImmutable($originalDate);
$modifiedDate->modify('+1 day');
echo $modifiedDate->format('m-d-Y');

Using DateTime eliminates the need to manually convert between formats (Y-m-d) and back. The internal representation of a date in PHP is a Unix timestamp, but the DateTime class acts as a wrapper that keeps your code readable and less prone to "timestamp math" errors. While converting to Y-m-d internally works, it adds unnecessary cognitive load and potential for format string typos.

For developers working within the Laravel ecosystem, this pattern aligns perfectly with how Eloquent handles casts or how Carbon (the date library often used alongside Laravel) simplifies these operations even further. If you are building a larger application where dates are critical, consider integrating the laravelcompany.com resources which often provide best practices for handling date serialization in their documentation, ensuring your API responses consistently use ISO 8601 standards internally while presenting human-readable formats to the client.

The takeaway is clear: avoid chaining strtotime() and date() unless you have a very specific legacy reason. Use DateTime or DateTimeImmutable to handle the parsing and arithmetic in one coherent step. This ensures that your variable $date remains usable later in your logic without unexpected formatting surprises.

Our network