如果指定时间之后添加另一天以交付 php


If time after specified add another day to delivery php

我想完成的事情是我们每周二和周四交货,我想限制如果订单在周一下午5点之后下达,那么他们必须等到周五。如果周四下午 5 点之后下订单,他们必须等到周二。

function freeDelivery($date){
    $holidays = array("05/30/2012","07/04/2012","09/05/2012","11/24/2012","11/25/2012","12/25/2012","12/31/2012","01/01/2013","05/28/2013","07/04/2013","09/03/2013","11/22/2013","11/23/2013","12/25/2013");
    $checkday = strtotime($date);
    // check if it's a holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }
    //sun
    if (date("w",$checkday) == 0) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +2 day");
    }
    //mon
    elseif (date("w",$checkday) == 1) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 days");
    }
    //tue
    elseif(date("w",$checkday) == 2) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +2 days");
    }
    //wen
    elseif (date("w",$checkday) == 3) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 days");
    }
    //thur
    elseif (date("w",$checkday) == 4) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +5 days");
    }
    //fri
    elseif (date("w",$checkday) == 5) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +4 days");
    }
    //sat
    elseif (date("w",$checkday) == 6) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +3 days");
    }
    // make sure it's not another holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }
    return $checkday;
}

上面的代码用于根据一周中的日期确定发货日期。

谢谢你的任何帮助,非常感谢。

假设你的意思是周一 5 点之后是星期四,然后周三 5 点之后你的意思是星期二......请尝试以下操作:

编辑最简单的方法是将代码添加回函数中。

function freeDelivery($date){
    $holidays = array("05/30/2012","07/04/2012","09/05/2012","11/24/2012","11/25/2012","12/25/2012","12/31/2012","01/01/2013","05/28/2013","07/04/2013","09/03/2013","11/22/2013","11/23/2013","12/25/2013");
    $checkday = strtotime($date);
    // check if it's a holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }
    $thedate = date("m/d/Y",$checkday);
    $dayofweek = date("w",$checkday);
    $dayincrease = array(0 => 2, 1 => 1, 2 => 2, 3 => 1, 4 => 5, 5 => 4, 6 => 3);
    $after5 = (date("G",$checkday) >= 17);
    $increase = "";
    if($after5 && $dayofweek == 1) {
        // monday after 5p = thurs
        $increase = "+3 days";
    } elseif($after5 && $dayofweek == 3) {
        // wednesday after 5p = tues
        $increase = "+6 days";
    } else {
        $increase = "+" . $dayincrease[$dayofweek] . " days";
    }
    $checkday = strtotime($thedate." ".$increase);
    // make sure it's not another holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }
    return $checkday;
}