Identify the days of the month from the number of the week PHP

-1

I have an event log where the user clicks on the desired day and a message appears if he wishes to repeat this event for the other days of the week. For example, if he clicked on 11/10/2018 (Thursday), I would like that when selecting this option, the registration would repeat on 10/18/2018 and 10/25/2018 which are also Thursday .

I understand that getting the day of the numeric week, I have to do it this way:

$diaSelecionado = $_POST["DiaSelecionado"]; // 11/10/2018
list($dia,$mes,$ano) = explode("/",$diaSelecionado);
$diaSemanaNumeral = date('w',mktime(0,0,0,$mes,$dia,$ano));

But how could I identify the next Thursdays (or any other day of the week depending on the date selected) and make the proper registration?

    
asked by anonymous 11.10.2018 / 23:16

2 answers

2

strtotime - Interprets any date / time description in English text in Unix timestamp. So we have to reverse the day with the month on the date.

ideone example

//$diaSelecionado = $_POST["DiaSelecionado"]; // 11/10/2018

$diaSelecionado = '11/10/2018';

echo date('d/m/Y', strtotime('+1 week', strtotime(str_replace('/', '-', $diaSelecionado))));

echo PHP_EOL;

echo date('d/m/Y', strtotime('+2 week', strtotime(str_replace('/', '-', $diaSelecionado))));
    
12.10.2018 / 01:59
1

Add 7 days to the current date:

date('d/m/Y', strtotime('+7 days'));

And it adds 7 days to each generated date:

echo date('d/m/Y', strtotime('+7 days', strtotime('18-10-2018')));

    
11.10.2018 / 23:26