php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18266 Wrong week output from date("W")
Submitted: 2002-07-10 16:46 UTC Modified: 2002-07-11 04:34 UTC
From: srabol at mail dot tele dot dk Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.2.1 OS: W2K
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: srabol at mail dot tele dot dk
New email:
PHP Version: OS:

 

 [2002-07-10 16:46 UTC] srabol at mail dot tele dot dk
print date("d-m-Y",mktime(0,0,0,12,31,2002)) . " Week : " . date("W",mktime(0,0,0,12,31,2002)) . "<br>";

The above line give this result:
31-12-2002 Week : 53

And according to my calendar there is no week 53 in year 2002

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-10 16:54 UTC] rasmus@php.net
According to the ISO date/time standards, Dec.31 2002 is indeed in week 53, so the output is correct.
 [2002-07-10 17:18 UTC] srabol at mail dot tele dot dk
Hi

Thanks for the quick answer.

Would you be so kind and point me to the definition of the ISO date/time specification.

print date("d-m-Y",mktime(0,0,0,12,30,2002)) . " Week : " .
date("W",mktime(0,0,0,12,30,2002)) . "<br>";

also state that the week is 53. I've just looked in 2 different 'paper' calanders and both of them says that Dec. 30 2002 and Dec. 31 2002 is week 1

OFF-TOPIC, sorry
My problem is that I need to know when a specific week in a year starts and ends.
 [2002-07-11 04:34 UTC] hholzgra@php.net
maybe you should use strftime() instead of date(),
it has support for different week counting schemes
(but be warned that PHP strftime() completely relies
on the systems c library implementation of strftime() 
for parsing the format string, and especially windows
is known for not supporting all of the documented 
format characters ...)

from http://php.net/strftime :

%U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week

%V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. (Use %G or %g for the year component that corresponds to the week number for the specified timestamp.)

%W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week 
 [2002-07-22 15:24 UTC] tmus at get2net dot dk
There is indeed a problem with the date('W'...) function in PHP 4.2.1... 

The ISO standard says that week 1 is the week that has the first thursday of the gregorian year, making the last week the week with the last thursday of the year (more/better info here http://www.merlyn.demon.co.uk/weekinfo.htm#WkNo )

But anyway, try making the following test...

print date("r (W)",1041289200)."<br>\n"; // Tue, 31 Dec 2002 00:00:00 +0100 (53)
print date("r (W)",1041375600)."<br>\n"; // Wed,  1 Jan 2003 00:00:00 +0100 (1)

So any way You decide to put it, at least the same week should not have two different numbers depending on the timestamp.
 [2002-07-22 15:29 UTC] tmus at get2net dot dk
Oh, just wanted to mention that Dec 31, 2002 is in fact Week 1 of 2003 and not 53 of 2002... That is because that week has the first thursday of 2003(actually 2003 starts on wednesday)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 13:01:28 2025 UTC