php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66453 Datetime modify bad result
Submitted: 2014-01-09 22:35 UTC Modified: 2014-01-09 23:24 UTC
From: mail at piotrantosik dot com Assigned:
Status: Not a bug Package: *Calendar problems
PHP Version: 5.5.7 OS: Linux
Private report: No CVE-ID: None
 [2014-01-09 22:35 UTC] mail at piotrantosik dot com
Description:
------------
DateTime object return non exist day in calendar.

Test script:
---------------
$d = new \DateTime('2014-01-08');
$d->modify('-8 day');

Expected result:
----------------
echo $d->format('Y-m-d')) //2013-12-30

Actual result:
--------------
echo $d->format('Y-m-d')) //2013-12-31

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-09 22:42 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-01-09 22:42 UTC] requinix@php.net
Are you saying that December 31st is not a day? Because it totally is.

The arithmetic is correct.
 [2014-01-09 23:01 UTC] mail at piotrantosik dot com
You're right, arithmetic is correct but 31-12-2013 is not exist in any calendars.
Eg. i need display a week from this day:
$d->format('W') return 01 - but maybe throw a exception? why return 01??
 [2014-01-09 23:24 UTC] requinix@php.net
December 31st, 2013 most certainly does exist, and it does in every Gregorian calendar-based system around. That's not even up for discussion, it simply *is*.

As for your question, read the documentation for date() [1] to see that "W" is the ISO 8601 week number [2], which is a two digit zero-padded number.

[1] http://www.php.net/date
[2] http://en.wikipedia.org/wiki/ISO_8601#Week_dates

If you have questions, please ask on a mailing list or online forum to get more help.
http://www.php.net/support.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC