This function returns an array of dates in between two dates.
Now it works completely fine, except for some unknown reason, if I put it the month of November or the month of March as the arguments, I get an array of one day less. The other months work completely fine. I am absolutely clueless.
function getListofDatesInRange2($fromDate, $toDate)
{
$fromDate = str_replace("-","/", $fromDate);
$toDate = str_replace("-","/", $toDate);
$dateMonthYearArr = array();
$fromDateTS = strtotime($fromDate);
$toDateTS = strtotime($toDate);
for ($currentDateTS = $fromDateTS; $currentDateTS <= $toDateTS; $currentDateTS += (60 * 60 * 24)) {
$currentDateStr = date("m-d-Y",$currentDateTS);
$dateMonthYearArr[] = $currentDateStr;
}
return $dateMonthYearArr;
}
I recoded it, and a while loop solved my issue. (although i have no idea what the issue was in the first place)
function getListofDatesInRange2($fromDate, $toDate)
{
$fromDate = str_replace("-","/", $fromDate);
$toDate = str_replace("-","/", $toDate);
$dateMonthYearArr = array();
$fromDateTS = strtotime($fromDate);
$toDateTS = strtotime($toDate);
array_push($dateMonthYearArr, date('m-d-Y', $fromDateTS));
while($fromDateTS < $toDateTS) {
$fromDateTS += 86400;
array_push($dateMonthYearArr, date('m-d-Y', $fromDateTS));
}
return $dateMonthYearArr;
}