note 116549 added to class.datetime

From: Date: Tue, 20 Jan 2015 23:17:07 +0000
Subject: note 116549 added to class.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-201479@lists.php.net to get a copy of this message
Be aware of this behaviour: <?php $dt1 = new \DateTime( '2014/12/31' ); $dt1->modify( '-1 month' ); $m = (int) $dt1->format( 'm' ); var_dump( $m ); // still 12 !!! $dt2 = new \DateTime( '2014/12/30' ); $dt2->modify( '-1 month' ); $m = (int) $dt2->format( 'm' ); var_dump( $m ); // 11 ?> The method modify( '-1 month' ) appear to remove 30 days, not to subtract 1 from the month and adjust the day (if needed). In my opinion, the former date should be adjusted to 2014/11/30, that is, the last day in the previous month. ---- Server IP: 72.52.91.14 Probable Submitter: 177.107.249.200 ---- Manual Page -- http://php.net/manual/en/class.datetime.php Edit -- https://master.php.net/note/edit/116549 Del: integrated -- https://master.php.net/note/delete/116549/integrated Del: useless -- https://master.php.net/note/delete/116549/useless Del: bad code -- https://master.php.net/note/delete/116549/bad+code Del: spam -- https://master.php.net/note/delete/116549/spam Del: non-english -- https://master.php.net/note/delete/116549/non-english Del: in docs -- https://master.php.net/note/delete/116549/in+docs Del: other reasons-- https://master.php.net/note/delete/116549 Reject -- https://master.php.net/note/reject/116549 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201479) next »