• support@answerspoint.com

CakePHP Search between 2 Date Records


I am building a small Web App that lets users reserve Office Rooms and Equipment. For the Reservation they enter a Start and an End Date.

When a user tries to find out if any (for example) car is available on 2012-10-23, and the database holds reservation date records of Start: 2012-10-20 and End: 2012-10-25 for (lets say) all the cars, how do I include all the dates between my date entries in the search?

The $date variable gets it's value from the Date Search Form Field.

This, unfortunately does not work, and I can't figure out how to use daysAsSql for this query:

$conditions = array(
    'conditions' => array(
        '? BETWEEN ? AND ?' => array($date,'Equipment.date_start','Equipment.date_end'), 

$this->set('equipments', $this->Equipment->find('all', $conditions));




There is a simpler solution to this, but thanks for the help:

(As a condition in the find:)

array('Equipment.date_start <= ' => $date,
      'Equipment.date_end >= ' => $date
  • answered 7 years ago
  • Gul Hafiz

$start = date('Y-m-d');
$end = date('Y-m-d', strtotime('+1 month'));
$conditions = array('Event.start <=' => $end, 'Event.end >=' => $start);
$this->Event->find('all', array('conditions' => $conditions));
  • answered 7 years ago
  • Gul Hafiz

Your Answer

    Facebook Share        
  • asked 7 years ago
  • viewed 1481 times
  • active 7 years ago

Best Rated Questions