Hi I've created an array that has a Start Date that increases by a month and this happens by how many months there are. So if my StartDate was 10/10/15 and placed 3 into my for loop I would receive 10/10/15 10/11/15 10/12/15 10/01/16. My current problem is that I've added a new while loop to find out if some of the days of the months fall on either a Saturday or Sunday.Which I don't want I would like it to fall on a weekday. So ive created this loop and it works however I have another problem. If 10/11/15 fell on a Sunday my loop will change it to 11/11/15 Monday which is correct but the rest of dates after it will now follow the changed date example be 11/12/15, 11/01/16.
I want it change the date but still the other dates to still increase from the startdate (10/10/15) like 10/10/15, 11/11/15, 10/12/15, 10/01/16. How would I do this? I also understand some of my code may not be the best but I am just a beginner. Any help would be much appreciated.
$date = "2015-10-1"; //startdate
$lol = 2; //length of loan
$start = strtotime($date); //startdate
$currentdate = $start;
echo "<pre>";
$times_table = [];
$titles[] = [
'Version' => 'Version 5 ',
'Date' => 'Feb-16',
'Name' => 'gary',
'RandNum' => '80',
'PaymentType' => 'P',
'dtType' => 'Q',
];
$times_table = [];
for($i = 0; $i <= ($lol + 1) ; $i++){
$times_table[$i]['StartDate']= $date ;
$times_table[$i]['Version']= "v10" ;
$cur_date = date("M-y-D", $currentdate);
$times_table[$i]['DtMy']= "<strong>" . $cur_date . "</strong>" ;
$mthYr = date("M", $currentdate);
$nxtmth = " ";
// Loop that changes the day to a weekday
while($nxtmth != "Y" ) {
if( $cur_date = date("M", $currentdate) !== $mthYr){
$nxtmth = "Y";
$currentdate = strtotime('-1 days', $currentdate);
$cur_date = date("d-M", $currentdate);
$times_table[$i]['DtMy']= "<strong>" . $cur_date . "</strong>" ;
}
if ($cur_date = date("w", $currentdate) == 0 || $cur_date = date("w", $currentdate) == 6){
if ($nxtmth == "Y"){
$currentdate = strtotime('-1 day', $currentdate);
$cur_date = date("d-M", $currentdate);
$times_table[$i]['DtMy']= "<strong>" . $cur_date . "</strong>" ;
}
else{
$currentdate = strtotime('+1 day', $currentdate);
$cur_date = date("d-M", $currentdate);
$times_table[$i]['DtMy']= "<strong>" . $cur_date . "</strong>" ;
}
if(($cur_date = date("M", $currentdate)) !== $mthYr){
$nxtmth = "Y";
$currentdate = strtotime('-1 day', $currentdate);
$cur_date = date("d-M", $currentdate);
$times_table[$i]['DtMy']= "<strong>" . $cur_date . "</strong>" ;
}
}
if($cur_date = date("w", $currentdate) > 0 && $cur_date = date("w", $currentdate) < 6 ){
$cur_date = date("d-M", $currentdate);
$times_table[$i]['DtMy']= "<strong>" . $cur_date . "</strong>" ;
break;
}
}
$currentdate = strtotime('+1 month', $currentdate); //Adds 1 month
}
print_r($times_table);
echo "</ pre>";