|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34304 Date('w') return wrong number for sunday. Maybe a new week day parameter is req.
Submitted: 2005-08-30 12:11 UTC Modified: 2005-09-02 11:42 UTC
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: sandved at gmail dot com Assigned: derick
Status: Closed Package: Feature/Change Request
PHP Version: 6CVS, 5CVS, 4CVS OS: *
Private report: No CVE-ID:
 [2005-08-30 12:11 UTC] sandved at gmail dot com
The Date function have a day of the week parameter 'w'

This parameter should return 7 for sundays, not 0 to be ISO 8601 compilant

Why :
> w   Numeric representation of the day of the week	
> 0 (for Sunday) through 6 (for Saturday)

This week parameter do not return leading zeros when used like Date('o\WWw'), Date('o\-\WW\-w')

According to ISO 8601 monday is the first day of the week and sunday the last, numbereded 1 to 7

(Section 5.2.3 Week date states
In expressions of week dates
- day of the week is represented by one decimal digit. Monday shall be identified as day [1] of any calendar
week, and subsequent days of the same week shall be numbered in ascending sequence to Sunday (day [7]).) like:

Date       - Week (extended format YYYY-Www-D)
---------- - ----------
1997-12-29 - 1998-W01-1
1998-01-04 - 1998-W01-7
1998-01-01 - 1998-W01-4
1998-12-31 - 1998-W53-4
1992-01-01 - 1992-W01-3
1992-02-29 - 1992-W09-6
1992-12-31 - 1992-W53-4
1975-01-01 - 1975-W01-3
1975-12-28 - 1975-W52-7
1975-12-29 - 1976-W01-1

Here's a copy of the latest free online copy, only minor changes in the text
in the latest version from ISO - also see

Reproduce code:
Echo Date('o\-\WW\-w', strtotime('2 January 2005'))
Date('o\-\WW\-w', strtotime('9 January 2005'));

Expected result:

Actual result:
2005-W1-0 (leading zeros in week fixed in bug report


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-30 12:28 UTC]
It's returning what it's documented to return. (it is not some ISO standard it complies to but the PHP manual)

 [2005-08-30 12:42 UTC] sandved at gmail dot com
Is it possible then to add a (ISO day) parameter which return 1 for monday, 2 for tuesday, ..., 6 for saturday and 7 for sunday?
 [2005-08-30 16:23 UTC]
Yeah, but it's not a bug but missing feature.

 [2005-09-02 11:42 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Fixed for PHP 5.1 and 6 by adding the "N" modifier.
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Sun Oct 04 23:01:29 2015 UTC