Skip to main content
Inspiring
July 24, 2014
Question

PHP DateInterval Problem

  • July 24, 2014
  • 1 reply
  • 562 views

I'm trying to get estimated delivery dates for various products but rather than working it out for each product it adds the previous delivery time onto the next product before working it out.

This is what I've got so far

[code]

public function getDeliveryDate() {

       $ndd = $this->getPhysicalOrderProducts();

        $arrive = $this->getPostDate();

        $arrive->add(new DateInterval('P'.$ndd[0]->getDeliveryTime().'D'));

        return $arrive;

      }[/code]

I want it get a product, add the DeliveryTime to PostDate then return that as $date I then want it to go on to the next product and do the same thing. At the moment what's happening is it's getting the date, adding the delivery time. Then with the next date it's adding the previous delivery time to the result of $date from the previous product.

Is there anyway to get it to recalculate it from fresh for every product?

This topic has been closed for replies.

1 reply

Rob Hecker2
Legend
July 24, 2014

Based on the code provided, I would try setting $arrive to NULL right after you return it. See if that does it.

return $arrive;

$arrive=NULL;

}

Inspiring
July 24, 2014

I tried that but unfortunately it didn't work at all.