Adding hours in PHP validating holidays -
i have php code generates delivery date , time of order in system validating schedule , sundays, in way:
<?php $hours = 6; $date = date('y-m-d h:i a'); $delivery = date("d-m-y h:i a", strtotime("+$hours hours", strtotime($fecha))); echo $delivery; if (date('h') >= 18 || date('h')<9 || date('w')==0){ $c=strtotime("tomorrow 09:00"); $date = date("y-m-d h:i a", $c); $delivery = date("d-m-y h:i a", strtotime("+$hours hours", strtotime($fecha))); echo $delivery; } ?>
this validates if order made after 6pm or before 9am or if current day sunday, order goes next day @ 9am , incrementing hours. want validate if current day , next day sunday or holidays 4th july (04-07) or xmas (25-12) generate delivery date time in next day of them (05-07 or 26-12).
how can modify it?
i help.
just run code in while-loop can call tomorrow 09:00
many times necessary:
$hours = 6; $orderpickup = time(); // order should picked right $delivery = strtotime("+$hours hours", $orderpickup); while( date('h', $orderpickup) > 18 || date('h', $orderpickup) < 9 || date('w', $orderpickup) == 0 // no order pickup on sunday || date('m-d', $orderpickup) == '12-25' // no order pickup on christmas-day || date('w', $delivery) == 0) // no delivery on sunday || date('m-d', $delivery) == '12-25' // no delivery on christmas-day ) { // $orderpickup 9 next day $orderpickup = strtotime('tomorrow 9:00:00', $orderpickup); $delivery = strtotime("+$hours hours", $orderpickup); // if tomorrow 9:00 stil not suitable, while-loop run again } echo "delivery on " . date("d-m-y h:i a", $delivery);
Comments
Post a Comment