That is what you said the first time. I just didn't read carefully enough. Sorry.
This should work:
function next_nth_wkday_ts($n, $day, $add_days = 0)
{
$wkdays = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
$now = strtotime('today');
$current_ts = strtotime('+' . $add_days . ' days', $now);
$first_dom_ts = strtotime(date('Ym01', $current_ts));
$first_dom_day_num = date('w', $first_dom_ts);
if (!($day_num = array_search(strtolower($day), $wkdays))) {
return false;
}
$first_day = $day_num - $first_dom_day_num + 1;
if ($day_num < $first_dom_day_num) {
$first_day += 7;
}
$nth_wkday_ts = strtotime(date('Y-m-' . $first_day, $current_ts) . '+' . ($n - 1) . ' weeks');
if ($now > $nth_wkday_ts) {
$nth_wkday_ts = next_nth_wkday_ts($n, $day, date('t', $first_dom_ts));
}
return $nth_wkday_ts;
}
Usage:
echo 'Next meeting: ' . date('Y-m-d', next_nth_wkday_ts(2, 'Thursday'));