Home Tutorial Php Phpdate PHP Date add days


Share on Google+Share on Google+
PHP Date add days
Posted on: August 24, 2009 at 12:00 AM
In this tutorial I will show you how you can add days into a date. The PHP Date add days example will show the way to add days, weeks, months etc.

In this example we will create sample code to add days or weeks to the date.

Following example show how to do date manipulation in PHP.

$currentDate = date("Y-m-d");// current date

echo "Current Date: ".$currentDate."<br>";

//Add one Date
$date = strtotime(date("Y-m-d", strtotime($currentDate)) " +1 day");
echo "Date After adding one day: ".date('l dS \o\f F Y', $date)."<br>";

$date = strtotime(date("Y-m-d", strtotime($currentDate)) " +1 week");
echo "Date After adding one week: ".date('l dS \o\f F Y', $date)."<br>";

$date = strtotime(date("Y-m-d", strtotime($currentDate)) " +2 week");
echo "Date After adding 2 weeks : ".date('l dS \o\f F Y', $date)."<br>";

$date = strtotime(date("Y-m-d", strtotime($currentDate)) " +1 month");
echo "Date After adding one month: ".date('l dS \o\f F Y', $date)."<br>";

$date = strtotime(date("Y-m-d", strtotime($currentDate)) " +30 days");

echo "Date After adding 30 days: ".date('l dS \o\f F Y', $date)."<br>";


Here is the output of the program:

Current Date: 2009-08-24
Date After adding one day: Tuesday 25th of August 2009
Date After adding one week: Monday 31st of August 2009
Date After adding 2 weeks : Monday 07th of September 2009
Date After adding one month: Thursday 24th of September 2009
Date After adding 30 days: Wednesday 23rd of September 2009



Related Tags for PHP Date add days:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 24, 2009

Recommend the tutorial

Advertisements Advertisements