0

I am having a serious issue I can not figure out. I am trying to return rows from MySQL database that have a Start date between two given dates and an End date as well. Here is my php code to query the database:

$getRooms = mysql_query("
    SELECT * 
    FROM Tarifas 
    WHERE Start BETWEEN '2013-01-10' AND '2013-01-13' 
    AND   End   BETWEEN '2013-01-10' AND '2013-01-13'
");

Start and End are set up as DATE fields

my database is set up as follows:

ID | RoomId | Start      | End
--------------------------------------
4  | 34562  | 2013-01-09 | 2013-10-23

If anyone can help me figure out why this is not working, it would be greatly appreciated!!

4

1 に答える 1

3

Looking at your query and sample data, perhaps you are looking for a SQL Query to Find Overlapping or Conflicting Date Ranges. The query would be:

SELECT *
FROM Tarifas 
WHERE '2013-01-13' >= `Start` AND `End` >= '2013-01-10'

2013-01-13 is greater than 2013-01-09 -- and -- 2013-10-23 is greater than 2013-01-10 so Tarifas #4 will be returned since it conflicts/overlaps with the specified dates.

于 2012-09-09T15:56:28.200 に答える