Celcius_Bitz Celcius_Bitz - 3 months ago 9
MySQL Question

select data from range of two column mysql

while this show everything between two dates, i want to make something that select data that only have "2013-11-28".

id Check_in Check_out
1 2013-11-01 2013-12-01
2 2014-01-01 2014-01-07
3 2013 11-20 2014-01-03


so when i select "2013-11-28", it will only select id '1' and '3'

thanks before.

JPG JPG
Answer

If you want to get records with Check_in's year is 2013 and month is 11, you can try this:

SELECT * 
FROM yourtable 
WHERE year(Check_in) = '2013' AND month(Check_in) = '11';

Demo Here

If you want to get records that Check_in is before 2013-11-28 and Check_out is after 2013-11-28, then you can try:

SELECT * 
FROM yourtable 
WHERE Check_in <= '2013-11-28' AND Check_out >= '2013-11-28';

Demo Here