Friday, 9 August 2013

Unable to add 30 days to date in PHP within loop

Unable to add 30 days to date in PHP within loop

I know there are countless other posts asking how to add days to an
existing date, but I'm not able to get it working.
Here, I'm trying to add 30 days to each date for each iteration of
$numPayments.
$numPayments = 5;
$nextPaymentDate = date('m-j-Y g:i a', strtotime("+30 days"));
for($i = 0; $i <= $numPayments; $i++) {
echo $nextPaymentDate . "\r\r";
$nextPaymentDate = date('m-j-Y g:i a', strtotime($nextPaymentDate . "
+ 30 days"));
}
For some reason, it just outputs the same date over again:
09-8-2013 3:10 pm
09-8-2013 3:10 pm
09-8-2013 3:10 pm
09-8-2013 3:10 pm
09-8-2013 3:10 pm
09-8-2013 3:10 pm

No comments:

Post a Comment