0

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Kin
  • 4,466
  • 13
  • 54
  • 106

2 Answers2

1

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)

Simon M
  • 2,931
  • 2
  • 22
  • 37
0

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.

Community
  • 1
  • 1
Lolito
  • 413
  • 3
  • 9