View Full Version : Help with php date constraint format
03-31-2004, 11:06 PM
First, thanks in advance to anyone why can help me with this problem. I am a newbie and have a date constraint problem. Is the following coded correctly? I can't seem to get it to work.
$dates = explode(":", $value);
$this->constraints .= "vehicle_reservations.start_date NOT BETWEEN '".$dates."' AND '".$dates."' AND
vehicle_reservations.end_date NOT BETWEEN '".$dates."' AND '".$dates."' AND ";
(vehicle_reservations.start_date IS NULL AND vehicle_reservations.end_date IS NULL) AND";
04-01-2004, 03:46 AM
What exactly are you trying to do? It looks like you want something close to the following:
$arrDateRange = explode(":",$value);
$firstDate = $arrDateRange;
$secondDate = $arrDateRange;
$startDate = $this->getStartDate();
$endDate = $this->getEndDate();
if($startDate <= $firstDate ||
$startDate >= $secondDate ||
$endDate <= $firstDate ||
$endDate >= $secondDate) break;
if($startDate=="" || $endDate=="") break;
Let me know if this is what you are aiming for because there are some quicker ways to execute this.
04-01-2004, 04:03 AM
Thanks for replying Hawkmoon,
This is for a search feature that displays motorhomes that are available for a selected date range. I am trying to make it so it will not display motorhomes in the database that are already booked for the selected dates (double booking!). $dates is the form beginning date, $dates is the form ending date. vehicle_reservations.start_date are the reservations in the database.
Currently the code is allows "double booking":
$this->constraints .= "(('".$dates."' < vehicle_reservations.start_date AND
'".$dates."' < vehicle_reservations.start_date) OR
('".$dates."' > vehicle_reservations.end_date AND
'".$dates."' > vehicle_reservations.end_date) OR
(vehicle_reservations.start_date IS NULL) AND
(vehicle_reservations.end_date IS NULL)) AND";
04-01-2004, 04:49 AM
Your AND/OR logic looks right. What values are $dates and $dates returning?
04-01-2004, 05:00 AM
Maybe if you looked at the page http://www.privatemotorhomerental.com/search.php?
Just click search and all coaches will be brought up but if you put in the dates it should exclude coaches that are already booked.
04-01-2004, 05:27 AM
Make sure all your dates in the database are in yyyymmdd format and the following code would work.
$sDay = $_POST['pcf_start_date_day'];
$sMonth = $_POST['pcf_start_date_month'];
$sYear = $_POST['pcf_start_date_year'];
$eDay = $_POST['pcf_end_date_day'];
$eMonth = $_POST['pcf_end_date_month'];
$eYear = $_POST['pcf_end_date_year'];
$sDate = $sYear . $sMonth . $sDay;
$eDate = $eYear . $eMonth . $eDay;
$sql = "SELECT * FROM ###your_database_name### ";
$sql .= " WHERE ";
$sql .= " vehicle_reservations.end_date < $sDate"; //Current Reservation ends before the queried date starts.
$sql .= " AND vehicle_reservations.start_date > $eDate"; //Current Reservation starts after the queried date ends
$result = mysql_query($sql);
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.