2008/7/31 <[EMAIL PROTECTED]> > > Hi everybody! > > This might be the right mailing list and it might not be. > > I'm having a problem getting date_diff to work. > I know date_diff accepts 2 DateTime objects and returns a DateInterval which > I var_dump but it shows nothing > Help is required! > > Regards > Andy > > Heres my code: > > <?php > > $date = new DateTime("28-July-2008"); > $other = new DateTime("31-July-2008"); > > $diff = date_diff($date, $other); > > echo '<br />date: '; > var_dump($date); > > echo '<br /><br />other: '; > var_dump($other); > > echo '<br /><br />diff: '; > var_dump($diff); > > echo '<br /><br />get_class_methods - DateInterval : '; > $class_methods = get_class_methods(new DateInterval('P2Y2M2D')); > foreach ($class_methods as $method_name) { > echo "$method_name(), "; > } > > echo '<br /><br />get_class_methods - DateTime : '; > $class_methods = get_class_methods(new DateTime("31-July-2008")); > foreach ($class_methods as $method_name) { > echo "$method_name(), "; > } > > ?> > > Heres my output: > > > date: object(DateTime)#1 (3) { ["date"]=> string(19) "2008-07-28 00:00:00" > ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/London" } > > other: object(DateTime)#2 (3) { ["date"]=> string(19) "2008-07-31 00:00:00" > ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/London" } > > diff: object(DateInterval)#3 (0) { } > > get_class_methods - DateInterval : __construct(), format(), > createFromDateString(), > > get_class_methods - DateTime : __construct(), __wakeup(), __set_state(), > createFromFormat(), getLastErrors(), format(), modify(), add(), sub(), > getTimezone(), setTimezone(), getOffset(), setTime(), setDate(), > setISODate(), setTimestamp(), getTimestamp(), diff(), > >
<?php $date = new DateTime("28-July-2008"); $other = new DateTime("31-July-2008"); $interval = date_diff($date, $other, True); date_add($date, $interval); var_dump($date); date_add($date, $interval); var_dump($date); outputs ... object(DateTime)#1 (3) { ["date"]=> string(19) "2008-07-31 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/London" } object(DateTime)#1 (3) { ["date"]=> string(19) "2008-08-03 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/London" } So, I can get the difference of 2 dates into an interval. I can then add that interval to other dates. I can't determine the value of the interval though. No interface for that. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"