PHP Stops Producing Dates After December 31st

Hi guys,

I’ve created a booking form on my website for people to book appointments from a list of dates. I have it set to produce 120 days from the current day. It’s been working fine all year but since the 120th day has hit December 31st/Jan 1st it’s no longer producing the list. I can only assume this is due to it trying to look further than December in the same year - which there obviously isn’t any more days in this year… So, how do I get it to start a new year, from Jan 1st…?

Any help would be great.


<option selected disabled value="select-date">Select a date</option>
												
	<?php

		date_default_timezone_set('Europe/London');
																	
		// Start date
		$date = date('l jS F');
		// End date
		$end_date = date('l jS F', strtotime("+120 days"));

		while (strtotime($date) <= strtotime($end_date)) {

		echo "<option value=\\"$date\
\\">$date\
</option>";

		$date = date ('l jS F', strtotime("+1 days", strtotime($date)));
		
		}

	?>

</select>
							
							

Okay, so the issue because quite clear once I put the following outside your while loop:

var_dump($date, strtotime($date), $end_date, strtotime($end_date));

In short, because your date strings do not contain a year, it is comparing September 2013 and January 2013 (instead of January 2014). I ultimately ended up with something like the following:

<option selected disabled value="select-date">Select a date</option> 
                                                    
    <?php  

        date_default_timezone_set('Europe/London'); 
                                                                     
        // Start date
        $date = date('Y-m-d');
        // End date
        $end_date = date('Y-m-d', strtotime("+120 days"));

        while (strtotime($date) <= strtotime($end_date)) {
        $outputDate = date('l jS F', strtotime($date));
        echo "<option value=\\"$outputDate\
\\">$outputDate\
</option>"; 

        $date = date ('Y-m-d', strtotime("+1 days", strtotime($date)));
         
        } 

    ?>  

</select>

Fantastic, I knew it would be simple.

Many thanks