Link to home
Start Free TrialLog in
Avatar of ZumbaJr
ZumbaJrFlag for Brazil

asked on

date("W") returns 52 to first days in a year

Hi Experts!

Why first days of year can be in a week of previous year when using:

echo date("W", strtotime("2011-01-01"));

It returns 52.

Somebody can help me to fix it?

Thanks in advance!
SOLUTION
Avatar of Garry Glendown
Garry Glendown
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's not broken.

The issue is that the weeks start on Monday.  http://php.net/manual/en/function.date.php

    January 2011
Su Mo Tu We Th Fr Sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

Open in new window


January 1st and 2nd thus belong to 2010 because they are before the first Monday.  52 is correct.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial