Jump to content

php calender help


lJesterl

Recommended Posts

I have a question and no idea what to do. I'm working on a date booking script. I have booked dates entered into a table. I.e 03/28/2008 or 04/02/2009 if those dates exist then it states $date not available. Here is the code im using. This part works.

 


$result=mysql_query("SELECT count(*) as numrecords FROM blockeddates WHERE date='$ADate'"); 
$row=mysql_fetch_assoc($result);
if ($row['numrecords'] >= 1){

$isavailable="$ADate Is Not Available";

} else {
$isavailable="$ADate Is Available";
}


$out[main]=$out[main]."

<b>$isavailable</b>
";

 

Now my problem is that the packes are 3 day vacations. I need to be able to check if they put 04/01/2008 I need to to check dates 04/01/2008, 04/02/2008, and 04/03/2008 to make sure there not booked instead of just 04/01/2008. I have no idea how to do that with getting the year and how many days per month etc. Can anyone help me?

Link to comment
Share on other sites

There are a whole bunch of functions the developers of PHP have made available to you. 

 

Please review the following:

 

www.php.net/date

www.php.net/mktime

 

Then have a look at this helpful snippet I am giving to you freshly ripped out of same report I wasted all day on.  It will give you an idead of using those two functions in conjunction with eachother.

 

		$startWeek = date('Y-m-d', mktime(12,0,0,date('m'),date('d')-date('w'),date('Y')));
	$endWeek = date('Y-m-d', mktime(12,0,0,date('m'),date('d')-date('w')+6,date('Y')));

 

Happy learning...

Link to comment
Share on other sites

i've almost got it, i just need to change some things. Here is my code.

 


if($packagedays=="4 Days 3 Nights"){

$number="3";

}else{

$number="2";

}

$startDate = date("m/d/Y", mktime(0, 0, 0, 3, 30, 2008));
$endDate = date("m/d/Y", mktime(0, 0, 0, 3, 30+$number, 2008));
$i=0;
while ($temp <> $endDate) {
echo " <br> ";
echo $temp = date("m/d/Y", mktime(0, 0, 0, 3, 30+$i, 2008));
echo " <br> ";
$i++;
};



 

ok I need to make the start date the variable $ADate and the enddate $number days past $ADate

 

right now on a 3 Day 2 Night Vacation it list

 

03/30/2008

 

03/31/2008

 

04/01/2008

 

because i have the date in that code set to 03/30/2008 but I need ot the $ADate that im sending from a previous page. Please help

Link to comment
Share on other sites

Fantastic! That works and list the days just the way I want them. Here is my code

 

 


$result=mysql_query("SELECT count(*) as numrecords FROM blockeddates WHERE date='$ADate'"); 
$row=mysql_fetch_assoc($result);
if ($row['numrecords'] >= 1){

$isavailable="$ADate Is Not Available";

} else {
$isavailable="$ADate Is Available";
}


if($packagedays=="4 Days 3 Nights"){

$number="4";

}else{

$number="3";

}

$Bdate = date('m/d/Y', strtotime("$ADate +$number days"));


$out[main]=$out[main]."

<b>$isavailable</b><br><br>

$starweek<br>
$endweek<br>

$year<br>
$packagename<br>
$pa[price]<br>
$packagedays<br>
$gifts<br>
$ADate - $Bdate
";

 

Now I need to take this to the last step. Lets say I choose 03/31/2008 This code lists

03/31/2008 - 04/03/2008

 

Now what I want to accomplish is to check and see if $ADate, $Bdate, and the dates between are in the blockeddates table using what I have. I am able to check $ADate and $Bate but not the dates in between. Any suggestions?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.