How to take out all lines that are not between two dates?

For example, I have two columns in my database:

Date1 and Date2. I am putting in my input fields (field1 = 12/11/14 and field2 = 22/11/14). So I want to take all rows in the table that have a lower date than 12/11/14

and above 22/11/14

. What should my request look like?

I'll make my question clearer.

Here is my DB:

enter image description here

So, I put in a rent_date

customer who rents a car from 11/12/14

and will return it to 11/22/14

. There are 5 clients, and only one is renting a car between the points 11/12/14

and 11/22/14

so I want to select the other 4 clients who do not rent a car between these two dates. I hope I understand. :)

+3


source to share


3 answers


If you want to know the records whose lease and return dates are not in a given range, you can use a query by comparing date

as follows:



SELECT * FROM DB WHERE rent_date < '2014-11-12 00:00:00' OR return_date > '2014-11-22 23:59:59'

      

0


source


I believe you can just use an operator BETWEEN

to check that rent_date is not in between your intervals, for example:



SELECT *
FROM myTable
WHERE rent_date NOT BETWEEN '2014-11-12' AND '2014-11-22'

      

+1


source


You need to use a range query.

SELECT foo FROM bar WHERE timestamp BETWEEN timestamp1 AND timestamp2

      

0


source







All Articles