Req #66610 [Opn->Nab]: +1 Month on Leap Year

From: Date: Thu, 30 Jan 2014 09:53:48 +0000
Subject: Req #66610 [Opn->Nab]: +1 Month on Leap Year
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184089@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66610&edit=1 ID: 66610 Updated by: rasmus@php.net Reported by: me at jacobt dot com Summary: +1 Month on Leap Year -Status: Open +Status: Not a bug Type: Feature/Change Request Package: Date/time related Operating System: Centos 6 PHP Version: 5.5.9RC1 Block user comment: N Private report: N New Comment: There is no right way here. We follow the GNU standard on this one as does many, if not most, other UNIX utils which means when you say you want to add a month, we increment the month, then adjust to make sure this falls on a valid date. Feb.30 is not valid, but it is 2 days after Feb.28 which is March 2. If we didn't do this when adding a month to Jan.28, Jan.29 and Jan.30 would all give you the same result. Try the same in sqlite or even from your Linux command line: $ date --date='+1 month' +'Next month is %B?' Next month is March? See: http://www.gnu.org/software/tar/manual/html_node/Relative-items-in-date-strings.html#SEC120 The solution is to be more specific about what you actually want. If you want the last day of next month, then say so. eg. "last day of next month" or "first day of next month" Previous Comments: ------------------------------------------------------------------------ [2014-01-30 08:01:10] me at jacobt dot com Description: ------------ Please check out the following example... http://codepad.viper-7.com/1Scqvd I'm not sure who thought this was the right thing to do, but it's not. For how MySQL handles it... mysql> SELECT DATE_ADD('2009-01-30', INTERVAL 1 MONTH); -> '2009-02-28' I find that more acceptable. Or, what I would actually prefer is March 1. If you're going to add time, which is basically what you're doing here b/c a month isn't a set number of days, add the minimum number required to get the job done, no more than that... Test script: --------------- http://codepad.viper-7.com/1Scqvd Expected result: ---------------- It should be clear in the file and description ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66610&edit=1

« previous php.bugs (#184089) next »