3

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

Matt Asbury
  • 5,644
  • 2
  • 21
  • 29
jannej
  • 864
  • 14
  • 26
  • 6
    That calendar is showing January **2010** – Matt Asbury Feb 11 '11 at 10:26
  • Sorry for the confusion! It actually seems to be a bug in iStat Menus. The 24th of January 2011 is a Monday if you check your caledar. I wish there was some way to edit my question with a correct image! – jannej Feb 11 '11 at 10:31
  • 1
    I have edited the image for you. – Matt Asbury Feb 11 '11 at 10:53
  • Using the same example code on my `PHP Version 5.3.2-1ubuntu4.7` offers the behaviour that you are expecting, so I am confused... What `LC_TIME` locale setting are you using? It could indeed be related, even though I can't see why a week would start on a Tuesday in any locale. It could also be a timezone issue. Your date of `2011-01-24` could be interpreted as the day before if your timezone offset is negative... – Eric Redon Feb 11 '11 at 10:54

1 Answers1

0

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!
Eric Redon
  • 1,712
  • 12
  • 21