Reputation: 12500
I'm making a small booking manager for my family's bed and breakfast.
I have a "booking" table that contains among other things a column called "arrivalDate" and a column called "departureDate".
I want to do a SELECT query where I retrieve all bookings that cover a certain date.
IE:
booking table:
name= John, arrivalDate= 01/01/2014, departureDate= 10/01/2014
name= Susie, arrivalDate= 04/01/2014, departureDate= 07/01/2014
I would like to do a query where it returns all bookings that are staying on 05/01/2014 In this case it would return both John's and Susie's booking.
Another query for 02/01/2014 would return only John's booking.
What would such an SQL query look like?
(NOTE: to not confuse anyone, the dates I put here are d/m/Y, I know that SQL uses Y/m/d, I can sort that myself, just looking for the logic)
Upvotes: 0
Views: 761
Reputation: 11579
select * from table where arrivalDate <= yourDate and yourDate <= departureDate
Replace yourDate
with date which you need (for example 05/01/2014
according to DB format).
Upvotes: 3