Week-number in PHP, again

1.9k Views Asked by At

We are using the ISO 8601-standard to show week numbers here in Sweden. Most people seems to be confused about this standard that week 1 can be in the former year. I am aware of this.

I have different strange problem, every date on a Monday is showing wrong week number. As far as I know weeks should start on Mondays according to this standard and the PHP manual. Have I missed something obvious? I am using PHP5.3.3. Thanks in advance!

$week = date('W', strtotime('2011-01-24')); //gives $week = 03

$week = date('W', strtotime('2011-01-25')); //gives $week = 04 correct!

According to my calendar 2011-01-24 should be week 4

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

It is most likely a timezone issue.

Try again by explicitly setting the timezone offset:

$week = date('W', strtotime('2011-01-24T00:00:01+0200')); // 03 - incorrect behavior
$week = date('W', strtotime('2011-01-24T00:00:01+0000')); // 04 - correct behavior!