php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54505 Date("Y") for certain years returns incorrectly
Submitted: 2011-04-11 16:35 UTC Modified: 2011-04-11 17:50 UTC
From: josh dot reinert at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.6 OS: Windows 7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: josh dot reinert at gmail dot com
New email:
PHP Version: OS:

 

 [2011-04-11 16:35 UTC] josh dot reinert at gmail dot com
Description:
------------
I am actually running PHP 5.3.5 on Apache 2.2 on Windows 7 as my development machine.

php.net states:
W 	ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)

I have a calender class that I created that lists the weeks of the year for a given month.  For certain years when January 1st is not on Sunday or Monday the date function is returning that it is still on the first week of the year where if the weeks start on Monday it should be returning the last week of the previous year.  This then offsets the rest of the year.  I noticed it when I had a Dec. with week 54.

Test script:
---------------
for ($i=2000; $i<2040; $i++){
//---- Week of the Year
    $WoY = (int) date("W", mktime(0, 0, 0, 1, 1, $i));
//---- Day of Jan 1st
    $DoM = date("l", mktime(0, 0, 0, 1, 1, $i));
//---- If the week is 1 then the day must be either Sunday or Monday; otherwise we are still in the previous year
    if ($WoY == 1 && !($DoM == "Monday" || $DoM == "Sunday"))
        print "$DoM Jan 1, $i is on week $WoY\n<BR>\n";

}

Expected result:
----------------
<BLANK>

Actual result:
--------------
Tuesday Jan 1, 2002 is on week 1
Wednesday Jan 1, 2003 is on week 1
Thursday Jan 1, 2004 is on week 1
Tuesday Jan 1, 2008 is on week 1
Thursday Jan 1, 2009 is on week 1
Tuesday Jan 1, 2013 is on week 1
Wednesday Jan 1, 2014 is on week 1
Thursday Jan 1, 2015 is on week 1
Tuesday Jan 1, 2019 is on week 1
Wednesday Jan 1, 2020 is on week 1
Wednesday Jan 1, 2025 is on week 1
Thursday Jan 1, 2026 is on week 1
Tuesday Jan 1, 2030 is on week 1
Wednesday Jan 1, 2031 is on week 1
Thursday Jan 1, 2032 is on week 1
Tuesday Jan 1, 2036 is on week 1
Thursday Jan 1, 2037 is on week 1
Wednesday Jan 1, 2039 is on week 1 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-11 16:39 UTC] josh dot reinert at gmail dot com
-Summary: Date("Y") for Dec returns incorrectly +Summary: Date("Y") for certain years returns incorrectly
 [2011-04-11 16:39 UTC] josh dot reinert at gmail dot com
Trying to modify the summary since it affects the year not just the month
 [2011-04-11 16:58 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2011-04-11 16:58 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Uh, what are you trying to do here? The year is the ISO-year, and the W an ISO-week number. Please read up on how that works here: http://en.wikipedia.org/wiki/ISO_year#Relation_with_the_Gregorian_calendar
 [2011-04-11 17:50 UTC] josh dot reinert at gmail dot com
Oh wow, sorry Derick. I miss interpreted the "weeks start on Monday" to include the first of the year.  As for what I am trying to do, our company uses the weeks of the year to calculate the "Month's End".  Our weeks actually start on Sunday's and according to one of our Accountants the first Sunday of the year is week 1.  I apologize for submitting a bad report.  Thank you for the information.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 05:01:34 2025 UTC