Identify days of the month from PHP week number

Asked

Viewed 79 times

-1

I have a register of events where the user clicks on the desired day and a message appears if he wants to repeat this event for the other days of the week. For example: if he click on the day 11/10/2018 (Thursday), I would like to select this option, the registration is repeated on the days 18/10/2018 and 25/10/2018 which are also Thursday.

I understand that taking the day of the numerical 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 appropriate registration?

  • What is the reason to deny the post?

  • 1

    I have really realized that many people negatively ask pertinent questions, which can.

  • 2

    My opinion, who is negative without comment is something of people who like to talk about what not to say!

2 answers

1

Sum 7 days to current date:

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

And add 7 days to each generated date:

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

1


strtotime - Interprets any date/time description on text in English in Unix timestamp. So we have to reverse the day with the month in 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))));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.