lJesterl Posted March 26, 2008 Share Posted March 26, 2008 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? Quote Link to comment Share on other sites More sharing options...
s0c0 Posted March 26, 2008 Share Posted March 26, 2008 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... Quote Link to comment Share on other sites More sharing options...
lJesterl Posted March 26, 2008 Author Share Posted March 26, 2008 I am completely lost on this portion of things. If anyone is interested I need to finish up this site. I need few adjustments made to the script if anyone can help. I can pay $30 paypal. Anyone? aim me LJesterL Quote Link to comment Share on other sites More sharing options...
Barand Posted March 26, 2008 Share Posted March 26, 2008 Something similar cropped up not long ago. See if these links help http://www.phpfreaks.com/forums/index.php/topic,172418.msg764729.html#msg764729 http://www.phpfreaks.com/forums/index.php/topic,183811.msg822544.html#msg822544 Quote Link to comment Share on other sites More sharing options...
lJesterl Posted March 27, 2008 Author Share Posted March 27, 2008 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted March 27, 2008 Share Posted March 27, 2008 <?php $Adate = '03/30/2008'; $duration = 3; $Bdate = date('m/d/Y', strtotime("$Adate +$duration days")); echo "$Adate - $Bdate"; ?> Quote Link to comment Share on other sites More sharing options...
lJesterl Posted March 27, 2008 Author Share Posted March 27, 2008 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? Quote Link to comment Share on other sites More sharing options...
lJesterl Posted March 27, 2008 Author Share Posted March 27, 2008 nm I got that part. One last question. What code can I use to check if $ADate is a Tuesday, Wednesday, or Thursday? We dont accept Tue, Wed, Thur arrivials on certain vacations. Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 27, 2008 Share Posted March 27, 2008 Convert the string to a timestamp Use the date('l', $stamp) or date('N', $stamp) function to find out the day of the week. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 27, 2008 Share Posted March 27, 2008 ... or if you want a numeric result, 0=Sunday, 1=Monday etc, $dow = date('w', strtotime($ADate)); Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 27, 2008 Share Posted March 27, 2008 the 'w' flag is better than the 'N' flag, as the n flag is only >= 5.1 and follows US standard (sunday being the first day of the week) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.