Home Tutorial Php Phpdate PHP date add, PHP Date addition to a date object

 
 

PHP date add, PHP Date addition to a date object
Posted on: August 30, 2009 at 12:00 AM
In this section we will see the several examples for date addition. You will see how easily you can add the dates.

In this section we will see the several examples for date edition. You will see how easily you can add the dates.

The use of strtotime() function in combination of date() function to add the days,years, months etc. to the current date.

<?php

$currentDate = date("Y-m-d");// current date
echo "Current Date: ".$currentDate."<br>";

$date30DaysAdded = date('Y-m-d', strtotime("+30 days"));
echo "30 Days added: ".$date30DaysAdded."<br>";

$date10YearsBack = date('Y-m-d', strtotime("-10 years"));
echo "10 Years back: ".$date10YearsBack."<br>";

$date2DaysAdded = date('Y-m-d', strtotime("+2 days"));
echo "2 Days Added: ".$date2DaysAdded."<br>";

?>

Program out put:

Current Date: 2009-08-30
30 Days added: 2009-09-29
10 Years back: 1999-08-30
2 Days Added: 2009-09-01

 

 

Related Tags for PHP date add, PHP Date addition to a date object:


Ask Questions?

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.