tags:

views:

244

answers:

3

Why is PHP date("W") showing that the current week is 2? Shouldn't it be on week 3?

In the PHP documentation it says: weeks starting on Monday. Does that mean it just ignored the first 3 days of this year?

+3  A: 

No, week 2 is correct.

Week number according to the ISO-8601 standard, weeks starting on Monday. The first week of the year is the week that contains that year's first Thursday. The highest week number in a year is either 52 or 53.

martin clayton
+1 beat me to it
Doug Neiner
this is also why the ISO year for 10-1-1 was 2009
The Guy Of Doom
A: 

I believe this means that the first three days of the year belong to the 52nd week of last year.

Chacha102
+1  A: 

2010-01-01 - 2010-01-03 are days in the 53th week that started on 2009-12-28.

edit: example script

$ts = strtotime('2009-12-27');
$end = strtotime('2010-01-26');

for($ts=strtotime('2009-12-27'); $ts<strtotime('2010-01-07'); $ts=strtotime('+1 day', $ts)) {
  echo date('Y-m-d W', $ts), "\n";
}

prints

2009-12-27 52
2009-12-28 53
2009-12-29 53
2009-12-30 53
2009-12-31 53
2010-01-01 53
2010-01-02 53
2010-01-03 53
2010-01-04 01
2010-01-05 01
2010-01-06 01
VolkerK