This topic is locked

calculate the delivery date

7/14/2018 4:26:33 PM
PHPRunner General questions
ruzgarajans author

hi,

scenario;

I am ordering and delivery time depends on order.

how do I calculate the delivery date?
Does the delivery change over time when the product changes?
table:

  1. Products tbl : "name (varchar) ", "order_preparation_time (TIME)"
  2. order tbl : "products_name (varchar)", "orderpreparation_time (TIME)", "date_of_registration (TIME)function now()", "delivery_time (time)


note:(order_preparation_time, it is not timezone , it is only minute counter )

for example: this order takes 45 minutes: order_preparation_time = 00:45:00
date_of_registration: 13:00:00 (now())

products_name : product A

order_preparation_time: 00:45:00
delivery_time : 13:45:00
I did not write the code because they all failed.
Can you help me please
thank you very much

ruzgarajans author 7/15/2018

i want to do,

I want to calculate the order delivery date instantly.
does this method work in date format?
https://xlinesoft.com/phprunner/docs/how_to_calculate_values_on_the_fly.htm
archive:
his example did not work on my application
http://asprunner.com/forums/topic/12902-calculating-dates-in-fhe-future/

// Before record added

function BeforeAdd(&$values,&$message,$inline)

{



$kpi = $values["kpi"];



if ($kpi == "2.1")

$kpidate = date("Y-m-d H:i:s", time()+7200);

else if ($kpi == "2.2")

$kpidate = date("Y-m-d H:i:s", time()+10800);

else if ($kpi == "3.1")

$kpidate = date("Y-m-d H:i:s", time()+14400);

else if ($kpi == "4.1")

$kpidate = date("Y-m-d H:i:s", time()+96400);

else if ($kpi == "4.2")

$kpidate = date("Y-m-d H:i:s", time()+86400);

else if ($kpi == "4.3")

$kpidate = date("Y-m-d H:i:s", time()+345600);

else if ($kpi == "4.4")

$kpidate = date("Y-m-d H:i:s", time()+2592000);

else if ($kpi == "4.5")

$kpidate = date("Y-m-d H:i:s", time()+15552000);



$values["data_fim"] = $kpidate;

} // function BeforeAdd
// Before record updated

function BeforeEdit(&$values,$where,&$oldvalues,&$keys,&$message,$inline)

{



$kpi = $values["kpi"];

$opendate = $values["data_abertura"];



if ($kpi == "2.1")

$kpidate = date("Y-m-d H:i:s", strtotime("$opendate + 120 minutes"));

else if ($kpi == "2.2")

$kpidate = date("Y-m-d H:i:s", strtotime("$opendate + 180 minutes"));

else if ($kpi == "3.1")

$kpidate = date("Y-m-d H:i:s", strtotime("$opendate + 240 minutes"));

else if ($kpi == "4.1")

$kpidate = date("Y-m-d H:i:s", strtotime("$opendate + 1 days"));

else if ($kpi == "4.2")

$kpidate = date("Y-m-d H:i:s", strtotime("$opendate + 1 days"));

else if ($kpi == "4.3")

$kpidate = date("Y-m-d H:i:s", strtotime("$opendate + 4 days"));

else if ($kpi == "4.4")

$kpidate = date("Y-m-d H:i:s", strtotime("$opendate + 30 days"));

else if ($kpi == "4.5")

$kpidate = date("Y-m-d H:i:s", strtotime("$opendate + 180 days"));



$values["data_fim"] = $kpidate;



} // function BeforeEdit
ruzgarajans author 7/16/2018

I need a clue to get started..

pls help me..

admin 7/16/2018

Your idea is correct but your syntax is wrong. Googling "PHP add days to date" we end up on this page

https://stackoverflow.com/questions/3727615/adding-days-to-date-in-php that shows us correct syntax.
Instead of

$kpidate = date("Y-m-d H:i:s", strtotime("$opendate + 120 minutes"));



you should use

$kpidate = date("Y-m-d H:i:s", strtotime($opendate." + 120 minutes"));