检查到达日期和离开是在mysql范围内

时间:2012-11-28 10:29:55

标签: php mysql zend-framework

我有以下表格:

id      travelStart travelExpires
1       2012-11-12  2013-01-31
1       2012-11-12  2013-01-31

以下是我的到达和离开日期:

arrival date: 2012-12-28
departure date   : 2012-12-30

我想在travelStart和travelEnd日期之间检查到达和离开日期。如何为它编写mysql查询。

2 个答案:

答案 0 :(得分:0)

您的答案是MySQL中BETWEEN运算符最简单的解决方案。工作原理:

SELECT * from YourTable WHERE ( :arrivalDate BETWEEN travelStart AND travelExpires) AND ( :departureDate BETWEEN travelStart AND travelExpires )

您显然需要绑定:arrivalDate:departureDate参数。

答案 1 :(得分:0)

尝试此查询

select * from table where (arrival_date<=travelStart AND arrival_date<=travelExpires) AND (departure_date>=travelStart AND departure_date<=travelExpires)