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
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.