Adding days to date field

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 1, 2009   (RSS)

By eduran582 - July 31, 2009

I have a date field I'd like to add X number of days to so I come up with a new date that I can use in an if, else test. I've tried using several date functions from the php.net site but still can't seem to come up with how this is done. It's probably one of those "can't see the forest for the trees" things, but at this point, I can't even get to the woods [tongue]

I found this function but am not sure how to utilize it:

//Use strtotime() function to convert any type of dates to timestamp
<?php
function addDayToDate($timeStamp, $totalDays=1){
// You can add as many days as you want. mktime will accumulate to the next month / year.
$thePHPDate = getdate($timeStamp);
$thePHPDate['mday'] = $thePHPDate['mday']+$totalDays;
$timeStamp = mktime($thePHPDate['hours'], $thePHPDate['minutes'], $thePHPDate['seconds'], $thePHPDate['mon'], $thePHPDate['mday'], $thePHPDate['year']);
return $timeStamp;
}
?>

Anyone had to "add" days to a date?

TIA!

Eric

Re: [eduran582] Adding days to date field

By eduran582 - August 1, 2009

Hi Dave,

Once again, right on the money! Just what I needed!

Interactivetools.com has the BEST user support I have ever seen and believe me, I've had my problems with others!

Thanks again for your superior support!

Eric