If I understand dates correctly you can assume that you will have a monday happening every 7 days.

And you can also safley assume that you will only have one monday each 7 days.
Anyway here is some code that prints you if its monday for the first time this month:
if ( date("D") === "Mon" && (date("j")) < 8 )
{
echo "Today is the the first Monday this month!";
}
- if ( date("D") === "Mon" && (date("j")) < 8 )
- {
- echo "Today is the the first Monday this month!";
- }
The code above will only check todays day and if it its the first monday this month then it will trigger and say that today.. bla bla bla. You wasn't asking for that.
Anyway here is some code that I wrote in a hurry:
$day = 1;
$month = 1;
$yearNow = 2011; //start counting from this year
$countToYear = 2020; // stop when reaching this year
while ($yearNow < $countToYear)
{
if ( $month == 6 ) //skip June (for some reason?)
{
$month++;
continue;
}
if ( date("l", mktime(0, 0, 0, $month, $day, $yearNow)) == "Monday" ) // prints out IF monday
{
echo date("Y-m-d", mktime(0, 0, 0, $month, $day, $yearNow));
echo "<br />";
}
$day++;
if ($day > 7) /* there are more than 7 days in a month but the first monday will happen in the first 7 days, so start over. with new month please */
{
$day = 1;
$month++;
if($month > 12)
{
$month = 1;
$yearNow++;
}
}
}
- $day = 1;
- $month = 1;
- $yearNow = 2011; //start counting from this year
- $countToYear = 2020; // stop when reaching this year
- while ($yearNow < $countToYear)
- {
- if ( $month == 6 ) //skip June (for some reason?)
- {
- $month++;
- continue;
- }
- if ( date("l", mktime(0, 0, 0, $month, $day, $yearNow)) == "Monday" ) // prints out IF monday
- {
- echo date("Y-m-d", mktime(0, 0, 0, $month, $day, $yearNow));
- echo "<br />";
- }
- $day++;
- if ($day > 7) /* there are more than 7 days in a month but the first monday will happen in the first 7 days, so start over. with new month please */
- {
- $day = 1;
- $month++;
- if($month > 12)
- {
- $month = 1;
- $yearNow++;
- }
- }
- }
Its not pretty but it should give you a list looking like:
2011-01-03
2011-02-07
2011-03-07
2011-04-04
2011-05-02
2011-07-04
2011-08-01
2011-09-05
2011-10-03
2011-11-07
2011-12-05
2012-01-02
2012-02-06
2012-03-05
2012-04-02
2012-05-07
2012-07-02
2012-08-06
2012-09-03
2012-10-01
2012-11-05
2012-12-03
2013-01-07
2013-02-04
2013-03-04
2013-04-01
2013-05-06
etc
These are the first time a monday is happening in each month. As you can see 20XX-06-XX is skipped since you didn't want to calculate when it happens on June. This is made by using a continue statment:
if ( $month == 6 )
{
$month++;
continue;
}
- if ( $month == 6 )
- {
- $month++;
- continue;
- }
You can check dates further in time or go back in time more by altering $yearNow and $countToYear's initial starting values. I would let the $day = 1; and $month = 1; values be as is, they are just telling it to start the first "scan" with month 1 and day 1.