Discover the next date from the day of the week

1

I'm developing 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 that it has to be PHP .

Day of the week:

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

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

This will be for infinite events ie every day during the week will appear an event.

Event1 - Monday

Event2 - Tuesday

etc etc ...

But for countdown I need 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.

I want to find out the next day that is Monday

    
asked by anonymous 13.02.2015 / 17:18

3 answers

2

You can create various algorithms to control these dates,

You 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.

I hope I have helped.

    
13.02.2015 / 17:58
1

Solution:

This prints the day of the following Monday

date('d', strtotime("next Monday"));
    
13.02.2015 / 19:53
0

You can use 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');

You can have simpler ways of doing this.

Spit has helped.

    
13.02.2015 / 17:42