In a procedural way, only with the information of the question:
$intervalo = 2; //2 em 2 semanas
$semanaAtual = array(0,0,1,0,0,0,0); //domingo, segunda, terça, quarta, quinta, sexta, sábado
$semanaProxima = array(0,0,0,1,0,0,0); //domingo, segunda, terça, quarta, quinta, sexta, sábado
$ultimoEvento = '2016-02-23'; //string contendo a data do último evento
$diaDaSemana = date("w", strtotime($ultimoEvento)); //dia da semana em que ocorreu o último evento
$dataProximoEvento = ''; //data do próximo evento
//verifica se dentro da própria semana ainda ocorrerá o evento
for($i=$diaDaSemana+1; $i<=6; $i++) {
if($semanaAtual[$i]) {
$dataProximoEvento = date("Y-m-d", strtotime($ultimoEvento . ' + ' . ($i-$diaDaSemana) . ' days'));
break;
}
}
//verifica qual o próximo dia do evento na próxima semana de acordo com o intervalo
if(empty($dataProximoEvento)) {
$primeiroDiaSemana = new DateTime(date('Y-m-d', strtotime("last Sunday", strtotime($ultimoEvento . ' + ' . (7*$intervalo) . ' days') )));
for($i=0; $i<=6; $i++) {
if($semanaProxima[$i]) {
$dataProximoEvento = date('Y-m-d', strtotime($primeiroDiaSemana->modify("+$i days")->format("Y-m-d H:i")));
break;
}
}
}
echo $dataProximoEvento;
What if the frequency is different for each week? What if in the same week the event still occurs? Or was this not to be considered? Look at the answer I posted.
– Filipe Moraes
Opa Flilipe, thanks, but the frequency is the same always, if it is different will be another event, and in the case I did, so I tested the user can occur the event several times in the week, as in the example, mon, qua and sex. I wonder if he found some mistake?
– Marcelo Diniz
In the example I posted too, you can have the same event in the same week, just change the arrays.
– Filipe Moraes