Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP DateInterval Problem

Explorer ,
Jul 24, 2014 Jul 24, 2014

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?

TOPICS
Server side applications
565
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 24, 2014 Jul 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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 24, 2014 Jul 24, 2014
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines