How to Add Days to a Date in PHP?


This example shows how to add days to a given date using the strtotime() function in PHP.

Syntax
$new_date =  date('Y-m-d', strtotime($given_date. ' + N days'));
Here is an example of adding 5 days to January 2, 2024
Example
<?php
  $given_date = "2024-01-02";
  $days_to_add = 5;
  $new_date =  date('Y-m-d', strtotime($given_date. " + {$days_to_add} days"));
  echo $new_date;
?> 

Output

2024-01-07

In this example, the strtotime() function is used to convert the given date into a Unix timestamp, and then add specific days. The result is formatted using the date() function with the 'Y-m-d' format.