PHP date add, PHP Date addition to a date object


 

PHP date add, PHP Date addition to a date object

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

 

 

Ads