CakePHP 在 2 个日期记录之间搜索 [英] CakePHP Search between 2 Date Records
问题描述
我正在构建一个小型 Web 应用程序,让用户可以预订办公室房间和设备.对于预订,他们输入开始日期和结束日期.
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.
当用户试图找出 2012 年 10 月 23 日是否有任何(例如)汽车可用时,数据库保存了开始日期:2012-10-20
和结束的预订日期记录:2012-10-25
对于(假设)所有汽车,我如何在搜索中包含日期条目之间的所有日期?
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?
$date
变量从日期搜索表单字段中获取它的值.
The $date
variable gets it's value from the Date Search Form Field.
不幸的是,这不起作用,我无法弄清楚如何使用 daysAsSql 进行此查询:
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
),
这篇关于CakePHP 在 2 个日期记录之间搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!