1

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?

superM
  • 8,605
  • 8
  • 42
  • 51
albanx
  • 6,193
  • 9
  • 67
  • 97
  • number of month in a week ..... ? what's that... or do you mean number of weeks in month...? – Sudhir Bastakoti Jun 21 '12 at 08:02
  • Do you want number of weeks or number of Mondays? – 472084 Jun 21 '12 at 08:05
  • more correct will be the number of weeks, the number of weeks – albanx Jun 21 '12 at 08:07
  • Did you see this: http://stackoverflow.com/questions/5853380/php-get-number-of-week-for-month – Sudhir Bastakoti Jun 21 '12 at 08:09
  • Depends what it is you need? There is between 28 and 31 days on a month which corrosponds to 4 weeks at least and at most 4 weeks and three days. So the quick answer would be you have 4 weeks in a month (always). – Repox Jun 21 '12 at 08:09
  • @Sudhir of course I saw that, but has nothing to do with this, and in my opinion that question has the wrong title, look at descritpion of that – albanx Jun 21 '12 at 08:10
  • @Repox yes but the best will be to have an exact calculation of weeks – albanx Jun 21 '12 at 08:11
  • @albanx That didn't really answer my question. What does 'exact calculation of weeks' mean? You wan't to know what weeks a month span over? – Repox Jun 21 '12 at 08:12
  • @Repox I just need to know the number of weeks in a standard way, ISO weeks number of a month – albanx Jun 21 '12 at 08:15

1 Answers1

2

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);
    }   
} 
Repox
  • 15,015
  • 8
  • 54
  • 79