dongzhi9574 2013-12-19 07:02
浏览 6
已采纳

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

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

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. 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.

  • 写回答

1条回答 默认 最新

  • dsafq2131321 2013-12-19 07:33
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计一个单管共射放大电路
  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架