Find out the next date from the day of the week

Asked

Viewed 2,271 times

1

I’m developing a CountDown for a date.

What I want is to receive the next day of the month from the day of the week. The problem is it has to be in PHP.

Weekday:

$dw = date( "w", $timestamp); ( 0 - domingo ... 6 - sabado )

Example: I want the next event on the day of the month that the day of the week 4 = Friday

This is going to be for infinite events IE, every day during the week will appear an event.

Event1 - Monday

Event2 - Tuesday

etc etc etc...

but for the countdown i need the date by ano/mes/dia

So I have to turn the day of the week into the next day of the month when the day of the week is the event.

For example. There will be an event next Monday the 16th.

The only data I have is that the event is every Monday.

then I want to find out the next day which is Monday

  • 1

    Your example was not clear kid. For example put something what you have and what you expect.

  • I believe his question is, when sending 0, to know what the next Sunday of the month will be, when sending 6, next Saturday, when sending 4, next Thursday, and so on...

  • Check out Edit please

3 answers

2


You can create several algorithms to control these dates,

can also use this:

$data_calculada =   date('d/m/Y', strtotime("+3 days",strtotime($DATA_CADASTRADA)));

In this example I add 3 days to my registered date and get the new date.

hope I’ve helped.

  • Yes it was more or less that, I will post my solution

1

Solution:

This prints the day next Monday

date('d', strtotime("next Monday"));

0

You can use the DateTime of PHP.

// seta a data como hoje.
$d=new DateTime();

// enquanto o dia da semana for diferente do dia da semana '5'
while (date('w', $d->getTimestamp()) <> '5') {
// adiciona 1 dia na data
 $d->add(new DateInterval('P1D'));
}

// imprime a próxima data com o dia da semana 5;
echo $d->format('d/m/Y');

There may be simpler ways to do this.

Skewer have helped.

Browser other questions tagged

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