note 108459 deleted from datetime.add by danbrown

From: Date: Thu, 10 May 2012 16:57:33 +0000
Subject: note 108459 deleted from datetime.add by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187620@lists.php.net to get a copy of this message
Note Submitter: sco ---- 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?

« previous php.notes (#187620) next »