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.
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.