lundi 5 juin 2017

How to create a date range with php?

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




Aucun commentaire:

Enregistrer un commentaire