So obviously I’m trying to generate a date that is recurring every 7 days for x number of weeks, it’s working every time the previous month had 31 days in it however when it runs after a month with 30, the generated day ends up being the day before the one it should be… I know if I run this math outside of php it works.
So if anyone has any idea why I might be losing a day for certain months I’d appreciate it!
[php]
while ($i <= $num_weeks) {
$month = date(m);
$year = date(Y);
if ($_POST[‘date’] == “”) {
$date = date(“Y-m-d”);
if ($i > 0) {
$change_week = ($i * 7);
$new_day = (date(d) + $change_week);
$num_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
if ($new_day > $num_days) {
while ($new_day > $num_days) {
$month++;
if ($month > 12) {
$year++;
$month++;
}
$num_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$new_day = ($new_day - $num_days);
}
$day = $new_day;
} else {
$day = $new_day;
}
if (strlen($day) == 1) {
$day = (“0” . $day);
}
if (strlen($month) == 1) {
$month = (“0” . $month);
}
$date = ($year . “-” . $month . “-” . $day);
}
}
}
[/php]