How to create a date range with php?

Viewed 17121

I tried to make time with PHP. start date of 2017-01-29 to 2017-12-29. But that happened I could not print in February because the month maximum of only 28 days. How to order printed anyway but with the February date up to 28.

my script:

date_default_timezone_set('UTC');

// Start date
$date = '2017-01-29';
// End date
$end_date = '2017-12-29';

while (strtotime($date) <= strtotime($end_date)) {
    echo "$date\n";
    echo "<br>";
    $date = date ("Y-m-d", strtotime("+1 month", strtotime($date)));
} 

Output:

enter image description here

4 Answers
Related