Doc #60353 [Opn->Csd]: Date-related "Relative Formats" doesn't indicate month behaviour

From: Date: Sun, 27 Nov 2011 03:59:00 +0000
Subject: Doc #60353 [Opn->Csd]: Date-related "Relative Formats" doesn't indicate month behaviour
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-7478@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60353&edit=1 ID: 60353 Updated by: frozenfire@php.net Reported by: frozenfire@php.net Summary: Date-related "Relative Formats" doesn't indicate month behaviour -Status: Open +Status: Closed Type: Documentation Problem Package: Documentation problem PHP Version: Irrelevant -Assigned To: +Assigned To: frozenfire Block user comment: N Private report: N New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2011-11-27 03:58:45] frozenfire@php.net Automatic comment from SVN on behalf of frozenfire Revision: http://svn.php.net/viewvc/?view=revision&revision=320010 Log: Added note regarding the behaviour of relative months. Closes bug #60353. ------------------------------------------------------------------------ [2011-11-21 22:05:44] frozenfire@php.net Description: ------------ A fellow on reddit.com/r/PHP mentioned that the documentation for Relative Formats for dates is missing information on how relative months work. Here's the relevant comment: http://www.reddit.com/r/PHP/comments/mk3ub/strtotime_wtf/c31lhav "echo date("Y-m-d", strtotime("+1 month 2011-11-30")); returns: 2011-12-30 // wtf? but I wanted 2011-12-31 This is why you don't use months when calculating dates. A month is ambiguous. Think about it - since months vary, which month is it supposed to use to calculate 1 month? November or December? Since The starting date is in November, it assumes that is the first month it should start calculating from. So, for the first iteration, 1 month is 30 days. However, it recalculates what a month is for every iteration. consider this: echo date("Y-m-d", strtotime("+1 month 2011-11-30")); // 2011-12-30 or 30 days echo date("Y-m-d", strtotime("+2 month 2011-11-30")); // 2012-01-30 or 61 days echo date("Y-m-d", strtotime("+30 days 2011-11-30")); // 2011-12-30 echo date("Y-m-d", strtotime("+60 days 2011-11-30")); // 2012-01-29 Notice how when I use +2 months it suddenly becomes 61 days. This is because it starts in December on the second iteration, and it recalculates what a month is based on that." This behaviour should be documented in the datetime.formats.relative document. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60353&edit=1

« previous php.doc.bugs (#7478) next »