-6

Example: $startdate = 01-Aug-2018 and $enddate = 04-Aug-2018

so, it should return an array with key date and value day name

array(
    "04-Aug-2018" => "Sat"
)

1 Answers1

1

This will do what you need, though you might want to tweak it to fit your project.

<?php

$date = '01-Aug-2018';
$date2 = '07-Aug-2018';

$period = new DatePeriod(
    new DateTime($date),
    new DateInterval('P1D'),
    new DateTime($date2)
);

$weekends = [];
foreach ($period as $key => $value) {
    if ($value->format('N') >= 6) {
        $weekends[$value->format('d-m-Y')] = $value->format('D');
    }  
}

var_dump($weekends);
MCMXCII
  • 1,043
  • 4
  • 13
  • 26