foreach with error

Asked

Viewed 40 times

1

Someone can give me a hand here, I made this train to take the weekdays, until all right, plus the foreach($periodo as $item) don’t list the last day, someone can tell me what I’m doing wrong!

$ini        = new DateTime('2019-02-01');
$fim        = new DateTime('2019-02-28');

$periodo    = new DatePeriod($ini, new DateInterval('P1D'), $fim);

foreach($periodo as $item){

if(substr($item->format("D"), 0, 1) != 'S'){

    echo  $item->format('d/m/Y') . " - " . $item->format("N") . " - " . $item->format("D") . "<br>";

    if($item->format("N") == 5){
        echo "<br><br>";
    }

}

}

1 answer

2


To put the last date in the list it is necessary to add a day to its end date, with the method modify()

$ini = new DateTime('2019-02-01');
$fim = new DateTime('2019-02-28');
$fim->modify('+1 day');

Browser other questions tagged

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