note 107610 modified in dateinterval.construct by danbrown

From: Date: Thu, 10 May 2012 20:38:33 +0000
Subject: note 107610 modified in dateinterval.construct by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187819@lists.php.net to get a copy of this message
As previously mentioned, to do a negative DateInterval object, you'd code: 

<?php
$date1 = new DateTime();
$eightynine_days_ago = new DateInterval( "P89D" );
$eightynine_days_ago->invert = 1; //Make it negative. 
$date1->add( $eightynine_days_ago );
?>

and then $date1 is now 89 days in the past. --was-- As previously mentioned, to do a negative DateInterval object, you'd code: $date1 = new DateTime(); $eightynine_days_ago = new DateInterval( "P89D" ); $eightynine_days_ago->invert = 1; //Make it negative. $date1->add( $eightynine_days_ago ); and then $date1 is now 89 days in the past. http://php.net/manual/en/dateinterval.construct.php

« previous php.notes (#187819) next »