CakePHP在2个日期记录之间搜索 [英] CakePHP Search between 2 Date Records

查看:100
本文介绍了CakePHP在2个日期记录之间搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个小型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:

(作为find:中的条件)

(As a condition in the find:)

array('Equipment.date_start <= ' => $date,
      'Equipment.date_end >= ' => $date
     ),

这篇关于CakePHP在2个日期记录之间搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆