Entry
increment in date variable
Feb 29th, 2008 09:46
dman, Edwin Chan, zahid bilal, http://www.ttnr.org
Let's say you want to increment 3 years, 2 months and decrement 1 day
to the current date variable:
<?php
// set the date variable to NOW
$date=mktime();
// Check the current date
echo "Date is now: ".date("d-M-Y",$date)."<BR>";
// add 3 years, 2 months and subtract 1 day
$years_to_add =3;
$months_to_add=2;
$days_to_add =-1;
$date=mktime(0,0,0,
date("m",$date)+$months_to_add,
date("d",$date)+$days_to_add,
date("Y",$date)+$years_to_add
);
// Check the current date again
echo "Date is now: ".date("d-M-Y",$date);
?>