I am making my own custom calendar application/script and have just finished with one of its functions
This function is to calculate the days of the month before the current month according to what day the current month started on and display them accordingly
I was able to get it working, but it doesn’t display the correct numbers all the time; some times it does and some times it doesn’t
you can view my calendar at http ( //troop557(.)vacau.com/calendar.php
this can be vied by going to march and see that the last month is supposedly 31 days long but go to that month, February and its only 28 days long
the code I came up with to get this to work is below, anyone know why its doing this?
[php]
$numDays = date(“t”, $currentTimeStamp);
$counter = 0;
for($i = 1; $i < $numDays+1; $i++, $counter++){
$monthstring = $month;
$monthlength = strlen($monthstring);
$daystring = $i;
$daylength = strlen($daystring);
$timeStamp = strtotime("$year-$month-$i");
$timeStamp_before = strtotime("$year-$month_before-$i");
$month_before = ($month == 1) ? "12" : $month-1;
$year_before = ($month == 1) ? $year-1 : $year;
$firstDay = date("w", $timeStamp);
$days_before = date("j", $timeStamp_before);
$days_before_thisMonth = $days_before - $firstDay;
$days_before_thisMonth = $days_before_thisMonth+1;
for($if1=0;$if1!=1 && $i < 2;$if1++){
$if_goes_over_check = ($days_before - $days_before_thisMonth) + 1;
}
if($i == 1) {
//$firstDay = ($firstDay > 4) ? $firstDay = 4 : $firstDay;
for($fd = 0; $fd < $firstDay; $fd++, $counter++, $days_before_thisMonth++) {
echo "<td>";
echo "<a href=\"?day=".$days_before_thisMonth."&month=".$month_before."&year=".$year_before."\" class=\"calendar-link\"";
echo ">".$days_before_thisMonth."</a><br />";
}
echo "</td>\r\n";
}
}
[/php]