简体   繁体   English

检查日期是周末或假日,请仔细检查

[英]Check date is weekend or a holiday, double check

Ok sorry about the wording on this one but it's doing my head in, I need to find the earliest delivery date, 好的,很抱歉这句话的措辞,但我正在努力,我需要找出最早的交货日期,

$useStartDate = mktime(0, 0, 0, date("m") , date("d")+1, date("Y"));

I have 2 functions 我有2个功能

The first checks to see if a date is a weekend or a Monday and increments it accordingly 第一个检查日期是周末还是星期一,并相应地增加日期

function checkWeekend ($CheckDateDate){
    if (date("w", $CheckDateDate) ==  1) { //monday
        return strtotime('+1 day', $CheckDateDate);
    }
    else if (date("w", $CheckDateDate) ==  0) { //sunday
        return strtotime('+2 day', $CheckDateDate);
    }
    else if (date("w", $CheckDateDate) ==  6) { //saturday
        return strtotime('+3 day', $CheckDateDate);
    }
    else {
        return 0;
    }
} 

The second check to see if the date is in my database of holidays 第二步检查日期是否在我的假期数据库中

function checkHoliday ($CheckDateDate) {
    $result = mysql_query("SELECT * FROM tblNonDeliveryDates Where NonDeliveryDate = '$CheckDateDate'");
    if (mysql_num_rows($result) > 0) {
        return strtotime('+1 day', $CheckDateDate);
    }
    else {
        return 0;
    }
}

Now what I want to do is check both functions until they both return 0, Where I'm having trouble going back and checking the date is not a weekend after it's been incremented because it's a Holidays. 现在,我要做的就是检查两个函数,直到它们都返回0,在这里我很难返回日期,因为日期是假期,所以检查日期不是周末,因为增加了假日。 This is what I have, but I know that it's wrong. 这就是我所拥有的,但是我知道这是错误的。

$CheckDate = $useStartDate;
while ($Checkdate > 0)
{
    $LastChecked = $CheckDate;
    $Checkdate = checkWeekend($CheckDate);
    $Checkdate = checkHoliday($CheckDate);
}
echo $LastChecked;

Hope that's clear. 希望很清楚。

You can try like this 你可以这样尝试

$CheckDate = $useStartDate;
while ($Checkdate > 0)
{
    $weekend = false;
    $holiday = false;

    if( checkWeekend($Checkdate) != 0)
        $weekend = true;
    else if( checkHoliday($Checkdate) != 0)
        $holiday = true;
    else
        $Checkdate = 0;

    if( $weekend )
       $Checkdate = checkWeekend($Checkdate);
    else if( $holiday )
       $Checkdate = checkHoliday($Checkdate); 

     $LastChecked = $Checkdate;
}
echo $LastChecked;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM