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
  • 34,719
  • 24
  • 185
  • 251
Kin
  • 4,306
  • 13
  • 50
  • 97

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,863
  • 2
  • 21
  • 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
  • 403
  • 3
  • 9