PHP Date add days


 

PHP Date add days

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 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.

<?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

 

Ads