Kin
Kin

Reputation: 4596

How to specific number of dates except sunday and saturday?

I need to get an array of dates except sunday and optional saturday by a specific day count... I found a cool thing - dateperiod, witch gives array to me, but how to exclude sunday and saturday?

Upvotes: 0

Views: 137

Answers (2)

Lolito
Lolito

Reputation: 412

As Simon M says, that seems to be the solution to this issue, it has been answered here too Get date range between two dates excluding weekends

It's a bit disconcerting there's not an option on DatePeriod to exclude days.

Upvotes: 0

Simon M
Simon M

Reputation: 2941

Try this...

$daterange = new DatePeriod(...);
$weekdays = [];
foreach($daterange as $date){
    if ($date->format("N") < 6) array_push($weekdays, $date);
}

$weekdays should now contain every date object that isn't the 6th or greater day of the week (that is, Saturday or Sunday)

Upvotes: 1

Related Questions