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

 
 

Share on Google+Share on Google+
PHP date add, PHP Date addition to a date object
Posted on: August 30, 2009 at 12:00 AM
Advertisement
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

 

 

Advertisement

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


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 30, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com