php.net |  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
Votes:3
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 (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 6CVS, 5CVS, 4CVS OS: *
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: sandved at gmail dot com
New email:
PHP Version: OS:

 

 [2005-08-30 12:11 UTC] sandved at gmail dot com
Description:
------------
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

http://se.php.net/date :
> 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


Sources
Here's a copy of the latest free online copy
http://www.pvv.org/~nsaa/8601v2000.pdf, only minor changes in the text
in the latest version from ISO - also see
http://en.wikipedia.org/wiki/ISO_8601.


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


Expected result:
----------------
2004-W53-7
2005-W01-7

Actual result:
--------------
2004-W53-0
2005-W1-0 (leading zeros in week fixed in bug report http://bugs.php.net/?id=34302)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-30 12:28 UTC] sniper@php.net
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] sniper@php.net
Yeah, but it's not a bug but missing feature.

 [2005-09-02 11:42 UTC] derick@php.net
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
http://snaps.php.net/.
 
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-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 03:01:28 2024 UTC