note 91977 modified in datetime.modify by danbrown

From: Date: Fri, 03 Jul 2009 13:07:04 +0000
Subject: note 91977 modified in datetime.modify by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157875@lists.php.net to get a copy of this message
Do not use '[+/-]{n} month' to get the last day of the month. If you use '+1 month' on the first of the month, it sets the date to the next first of the month. This behaviour gives the impression, that php considers the length of a month, which is not true. Basically if you use '+1 month' it takes the month number, adds 1 and parses result as a new date. But if you use '+1 month' on the last day of a month, the result is unexpected as 2009-05-31 becomes 2009-06-31 which is an invalid date and then interpreted as 2009-07-01. --was-- Do not use '[+/-]{n} month' to get the last day of the month. If you use '+1 month' on the first of the month, it sets the date to the next first of the month. This behaviour gives the impression, that php considers the length of a month, which is not true. Basically if you use '+1 month' it takes the month number, adds 1 and parses result as a new date. But if you use '+1 month' on the last day of a month, the result is unexpected as 2009-05-31 becomes 2009-06-31 which is an invalid date and then interpreted as 2009-07-01. http://php.net/manual/en/datetime.modify.php

« previous php.notes (#157875) next »