DateAdd Function on PHP

If you are looking for a DateAdd function for PHP then see the sample code below.
The function accepts day only as the interval.
< ?php
/* --- DateAdd() function ---*/
function DateAdd($interval) {
$curdate = getdate();
$cday = $curdate['mday']+$interval;
$cmonth = $curdate['mon'];
$cyear = $curdate['year'];
if ($cday > 30){
$cmonth = $cmonth + 1;
$cday = $cday - 30;
if ($cmonth == 13){
$cyear = $cyear + 1;
$cmonth = 1;
}
}
$ourDate = array($cyear,$cmonth,$cday);
return $ourDate;
}
/* ---------- End of DateAdd() function ----------*/
/*Example*/
print DateAdd(10); //add 10 days to the current date
?>
Modify the code and play with the interval type to fit for your needs.
If you have corrections, comments or suggestions, Please feel free to post it here.
Spread the word
del.icio.us Digg Furl Google StumbleUpon Technorati Windows Live Yahoo! Help












Leave a Comment