hi guys,
I have a calendar script that inputs the data into a database with a start date and an end date.
I'm trying to develop script that will search through the all the dates between the start date and the end date, and return true/false accordingly. (this is a basic 'check availability' script).
eg: if the start date is 01/04/2008, and the end date is 01/05/2008, and the user searches for 15/04/08, then the script needs to search through all dates between the start date and the end date, and if one of them matches return 'not available' etc.
here is what I have so far (thats not working!):
$searched_for = "2008-03-06";
$start = "2008-03-01";
$end = "2008-03-15";
$init_date = strtotime($start);
$dst_date = strtotime($end);
$r = strtotime($searched_for);
$offset = $dst_date-$init_date;
$dates = floor($offset/60/60/24) + 1;
for ($i = 0; $i < $dates; $i++)
{
$newdate = date("Y-m-d", mktime(12,0,0,date("m", strtotime($start)),
(date("d", strtotime($start)) + $i), date("Y", strtotime($start))));
echo $newdate ."<br>";
}
if ($r == $newdate) {echo "the date you searched for is within the date range"; } else { echo "the date you searched for is outside the date range"; }
any help greatly appreciated!!
Mark