Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with php date constraint format

    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.

    case "date_range":
    $dates = explode(":", $value);
    $this->constraints .= "vehicle_reservations.start_date NOT BETWEEN '".$dates[0]."' AND '".$dates[1]."' AND
    vehicle_reservations.end_date NOT BETWEEN '".$dates[0]."' AND '".$dates[1]."' AND ";
    (vehicle_reservations.start_date IS NULL AND vehicle_reservations.end_date IS NULL) AND";
    break;

    Thanks,
    MH

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    response

    Hey Mike,

    What exactly are you trying to do? It looks like you want something close to the following:

    case "date_range"

    $arrDateRange = explode(":",$value);
    $firstDate = $arrDateRange[0];
    $secondDate = $arrDateRange[1];

    $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.

    -Hawkmoon

  • #3
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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[0] is the form beginning date, $dates[1] 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[0]."' < vehicle_reservations.start_date AND
    '".$dates[1]."' < vehicle_reservations.start_date) OR
    ('".$dates[0]."' > vehicle_reservations.end_date AND
    '".$dates[1]."' > vehicle_reservations.end_date) OR
    (vehicle_reservations.start_date IS NULL) AND
    (vehicle_reservations.end_date IS NULL)) AND";

    Thanks,
    Mike

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Gotcha...

    Your AND/OR logic looks right. What values are $dates[0] and $dates[1] returning?

  • #5
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Make sure all your dates in the database are in yyyymmdd format and the following code would work.

    -Hawk

    PHP Code:
    //Start Date
    $sDay    $_POST['pcf_start_date_day'];
    $sMonth $_POST['pcf_start_date_month'];
    $sYear   $_POST['pcf_start_date_year'];

    //End Date
    $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); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •