PHP / MySQL - displays the list of dates for all Mondays of the year

advertisements

I need to populate a drop-down list on a form with dates for all Mondays in the next year?

What is the best way to do this? With a MySQL table populated with dates or is there a smarter method of generating these dates without the need for MySQL?

Desired output would be something like:

The value of the selected option would just be the date commencing, so for the first option in the image, 11 Mar 13 would be the value.

Thanks for the help and apologies if this is a silly question.


Edit: Modified to support passing in a start date rather than simply a year

function getDays($year, $startMonth=1, $startDay=1, $dayOfWeek='monday') {
    $start = new DateTime(
        sprintf('%04d-%02d-%02d', $year, $startMonth, $startDay)
    );
    $start->modify($dayOfWeek);
    $end   = new DateTime(
        sprintf('%04d-12-31', $year)
    );
    $end->modify( '+1 day' );
    $interval = new DateInterval('P1W');
    $period   = new DatePeriod($start, $interval, $end);

    foreach ($period as $dt) {
        echo $dt->format("d/m/Y") . '<br />';
    }
}

getDays(2013, 3, 12, 'monday');

Formatting of the output as a dropdown should be a straightforward exercise