Next month, same day in PHP
Posted
by Guillermo
on Stack Overflow
See other posts from Stack Overflow
or by Guillermo
Published on 2009-06-05T22:02:05Z
Indexed on
2010/03/31
23:33 UTC
Read the original article
Hit count: 421
I got a last time (and urgent) requeriment of an "event" that needs to be scheduled the same day of every month.
Say of you set the start date on the 1st May you should get the next events on the 1st of Jun, 1 Jul etc. The problem comes with a start date on the 31st (the next ones could be 30 or 28 depending on the month)
Considering that there are months with different numbers of days (28,30,31) depending on the month itself and the year... what would ba an easy way to setup this?
Consider the following (and flawed) nextmonth function:
$events = array()
function nextmonth($date) {
return $date+(60*60*24*30);
}
$curr = $start;
while($curr < $end) {
$events[ = $curr;
$curr = nextmonth($curr);
}
Edited to add: The problem for me is, simply enought, is to solve what the number of days of any given month is and thus get the next corresponding date..
© Stack Overflow or respective owner