albanx
albanx

Reputation: 6333

Find the real number of weeks in a month

Should I consider the number of weeks in a month the number of mondays it contains? Any way the final output I need is something like this:

Jan - week 1
Jan - week 2
Jan - week 3
Jan - week 4
Feb - week 5
Feb - week 6
Feb - week 7
Feb - week 8
...............

I searched but I didn't find a good answer to this question. Any help please?

Upvotes: 1

Views: 2511

Answers (1)

Repox
Repox

Reputation: 15476

This does what you ask:

for($i = 1; $i <= 12; $i++)
{
    $timestamp = mktime(0, 0, 0, $i, 1, 2012);
    while(date('n', $timestamp) == $i)
    {
        echo date('F', $timestamp).' - Week '.  date('W', $timestamp)."<br>";
        $timestamp = strtotime("+1 week", $timestamp);
    }   
} 

Upvotes: 2

Related Questions