0

I'm trying to create a function that calculates a delivery time based on today's date.

It needs to do the following:

  • if the time is less than 2pm ; add 3 days to today's date
  • if the time is greater add 5 days
  • if the 3/5 days land on a weekend, then the day needs to be Monday

I was wondering what the best approach would be?

Would it be worth putting valid days , i.e. into an array and checking if the date with days added is in it?

I have something like:

$date = time('H'):
If($date < '14') {
$delivery = date('Y-m-d', strtotime('+3 days')
}
else if($date > '14') {
$delivery = date('Y-m-d', strtotime('+5days')
}
return $delivery;
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
sipher_z
  • 1,221
  • 7
  • 25
  • 48

1 Answers1

0

check for hour and add days:

function returnDelivery(){
    $date = date('G');
    $delivery = 0;
    if($date < 14){
        $delivery = strtotime('+3 days');
    } else {
        $delivery = strtotime('+5 days');
    }

    if(date('w', $delivery) == 6 || date('w', $delivery) == 0){
        $delivery = strtotime('next monday');   
    }
    return $delivery;
}

echo returnDelivery(); // returns timestamp
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107