note 108459 added to datetime.add
| From: | sco | Date: | Fri, 27 Apr 2012 16:15:43 +0000 |
| Subject: | note 108459 added to datetime.add | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187382@lists.php.net to get a copy of this message | ||
Seeing as this add function manipulates the object itself instead of (or in addition to) returning a
new object with the result, how does one add an interval to a date, return the new date, and leave
the original as it was?
For example:
$date1 = new DateTime("2012-04-25");
$date2 = $date1->add(new DateInterval("P1Y"));
You would expect that:
$date1 = 2012-04-25
$date2 = 2013-04-25
But instead BOTH will = 2013-04-25!
So, how do you add a time interval to a date, return a result, but not change the original date?
----
Server IP: 69.147.83.197
Probable Submitter: 71.234.104.81
----
Manual Page -- http://www.php.net/manual/en/datetime.add.php
Edit -- https://master.php.net/note/edit/108459
Del: integrated -- https://master.php.net/note/delete/108459/integrated
Del: useless -- https://master.php.net/note/delete/108459/useless
Del: bad code -- https://master.php.net/note/delete/108459/bad+code
Del: spam -- https://master.php.net/note/delete/108459/spam
Del: non-english -- https://master.php.net/note/delete/108459/non-english
Del: in docs -- https://master.php.net/note/delete/108459/in+docs
Del: other reasons-- https://master.php.net/note/delete/108459
Reject -- https://master.php.net/note/reject/108459
Search -- https://master.php.net/manage/user-notes.php