Get List of Dates Between Two Dates using PHP

DatePeriod class

<?php

$dateFormat = 'Y-m-d';
$startDate = new DateTime('2020-11-20');
$endDate = new DateTime('2020-11-30');

$endDate->modify('+1 day');
$period = new DatePeriod($startDate, new DateInterval('P1D'), $endDate);

$dates = [];
foreach ($period as $date) {
    $dates[] = $date->format($dateFormat);
}

print_r($dates);

Leave a Comment

Cancel reply

Your email address will not be published.