php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20594 Date "W" switch returns 0 and 1 for First week randomly
Submitted: 2002-11-23 01:08 UTC Modified: 2002-11-23 08:30 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: evilk at ozline dot net Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.2.3 OS: FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: evilk at ozline dot net
New email:
PHP Version: OS:

 

 [2002-11-23 01:08 UTC] evilk at ozline dot net
using date and the "W" (shows the week number) switch. Will return the FIRST week number differantly depending on the year.

date("W", mktime(0,0,0,1,1,2000)); will return 0 
date("W", mktime(0,0,0,1,1,2001)); returns 1.

Only differance is the year. Here is a list of years and there first week vaules, including Leap year.

for ($q=2001; $q<2021; $q++) {
        $test1= date("W",  mktime(0,0,0,1,1,$q));
        $leap1= date("L",  mktime(0,0,0,1,1,$q));
        echo "Year: $q WeekNum: $test1 LeapYear: $leap1<br>";
}

Year: 2001 WeekNum: 1 LeapYear: 0
Year: 2002 WeekNum: 1 LeapYear: 0
Year: 2003 WeekNum: 1 LeapYear: 0
Year: 2004 WeekNum: 1 LeapYear: 1
Year: 2005 WeekNum: 0 LeapYear: 0
Year: 2006 WeekNum: 0 LeapYear: 0
Year: 2007 WeekNum: 1 LeapYear: 0
Year: 2008 WeekNum: 1 LeapYear: 1
Year: 2009 WeekNum: 1 LeapYear: 0
Year: 2010 WeekNum: 0 LeapYear: 0
Year: 2011 WeekNum: 0 LeapYear: 0
Year: 2012 WeekNum: 0 LeapYear: 1
Year: 2013 WeekNum: 1 LeapYear: 0
Year: 2014 WeekNum: 1 LeapYear: 0
Year: 2015 WeekNum: 1 LeapYear: 0
Year: 2016 WeekNum: 0 LeapYear: 1
Year: 2017 WeekNum: 0 LeapYear: 0
Year: 2018 WeekNum: 1 LeapYear: 0
Year: 2019 WeekNum: 1 LeapYear: 0
Year: 2020 WeekNum: 1 LeapYear: 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-23 01:09 UTC] evilk at ozline dot net
using date and the "W" (shows the week number) switch. Will return the FIRST week number differantly depending on the year.

date("W", mktime(0,0,0,1,1,2000)); will return 0 
date("W", mktime(0,0,0,1,1,2001)); returns 1.

Only differance is the year. Here is a list of years and there first week vaules, including Leap year.

for ($q=2001; $q<2021; $q++) {
        $test1= date("W",  mktime(0,0,0,1,1,$q));
        $leap1= date("L",  mktime(0,0,0,1,1,$q));
        echo "Year: $q WeekNum: $test1 LeapYear: $leap1<br>";
}

Year: 2001 WeekNum: 1 LeapYear: 0
Year: 2002 WeekNum: 1 LeapYear: 0
Year: 2003 WeekNum: 1 LeapYear: 0
Year: 2004 WeekNum: 1 LeapYear: 1
Year: 2005 WeekNum: 0 LeapYear: 0
Year: 2006 WeekNum: 0 LeapYear: 0
Year: 2007 WeekNum: 1 LeapYear: 0
Year: 2008 WeekNum: 1 LeapYear: 1
Year: 2009 WeekNum: 1 LeapYear: 0
Year: 2010 WeekNum: 0 LeapYear: 0
Year: 2011 WeekNum: 0 LeapYear: 0
Year: 2012 WeekNum: 0 LeapYear: 1
Year: 2013 WeekNum: 1 LeapYear: 0
Year: 2014 WeekNum: 1 LeapYear: 0
Year: 2015 WeekNum: 1 LeapYear: 0
Year: 2016 WeekNum: 0 LeapYear: 1
Year: 2017 WeekNum: 0 LeapYear: 0
Year: 2018 WeekNum: 1 LeapYear: 0
Year: 2019 WeekNum: 1 LeapYear: 0
Year: 2020 WeekNum: 1 LeapYear: 1
 [2002-11-23 08:26 UTC] michael dot mauch at gmx dot de
As stated in the manual, date("W", ...) returns the ISO8601 week number. The first week number of any year is always 1. But January, 1st is sometimes not in the first week of a year, but in the last week of the previous year. See e.g. <http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm> for details.
 [2002-11-23 08:30 UTC] derick@php.net
right, not a bug -> bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 15:01:29 2024 UTC