Home
» Web Development » PHP Add Days to Date
PHP Add Days to Date
| May 21, 2011 | Posted by The Futtock under Web Development |
Using the PHP functions date() and strtotime() we can easily take a date and add days to the date. We can also add weeks months and years.
// Set the current date:
$datetoday = date("Y-m-d");
// Add a day to the date:
$newdate = strtotime(date("Y-m-d", strtotime($$datetoday)) . " +1 day");
// Add a week to the date:
$newdate = strtotime(date("Y-m-d", strtotime($datetoday)) . " +1 week");
// Add a month to the date:
$newdate = strtotime(date("Y-m-d", strtotime($datetoday)) . " +1 month");
And so on.
PHP add days to date is simple. The variable $newdate gives us the changed date.
Recent Comments