hey guys...
i have found irregular behavior in my function (a modified version from existing function that i found in this forum). The function should calculate n display dates of every other fridays between two dates. The function works fine from month of January 2003 through September 2003. However, it suddenly miscalculate the dates at the end of October.
<?
function fof_dates($startdate,$enddate){
$startdate = strtotime($startdate);
$enddate = strtotime($enddate);
$i = $startdate;
while($i <= $enddate) {
$dates = $dates." ".date("Y-m-d",$i);
$i = $i + (86400*14);
}
$fof_ardates = explode(" ",$dates);
for($s=0; $s<=count($fof_ardates); $s++)
{
print "$fof_ardates[$s] <br>";
}
return $fof_ardates;
}
?>
<?
$sdate = "2003/09/19";
$edate = "2004/01/16";
$info = "FOF";
$foflistdates = fof_dates($sdate, $edate);
print "<p> </p>";
$sdate = "2003/05/02";
$edate = "2003/09/05";
$info = "FOF";
$foflistdates = fof_dates($sdate, $edate);
?>
here is the result it generates:
.
2003-05-02
2003-05-16
2003-05-30
2003-06-13
2003-06-27
2003-07-11
2003-07-25
2003-08-08
2003-08-22
2003-09-05
2003-09-19
2003-10-03
2003-10-17
2003-10-30
2003-11-13
2003-11-27
2003-12-11
2003-12-25
2004-01-08
.
as you can see...from 2003-05-02 to 2003-09-05, the dates are correct. But, from 2003-09-19 to 2004-01-16, it prints 2003-10-30 instead of 2003-10-31. it misses by 1 day. that causes miscalculation to the rest of the calculation.
Can some of you give me a little explanation about this problem? a solution for it will be greatly appreciated ... javascript:smilie('😉')
Thanks in advance...