Mysql: ¿seleccionar filas que no coinciden con un rango de fechas?

I have a table in mysql that holds a start and end date field. What I need to do is query this table to find all rows that do not match the date Im searching by. How would I do that? So if I used todays date and queried this table with it then I need to find all rows that this date does not fall between the start and end date in the table. Hope that makes sense!

preguntado el 31 de julio de 12 a las 10:07

4 Respuestas

Puedes usar BETWEEN clause to filter records based on date range and to exclude that date range you can use NOT cláusula como:

FROM my_table 
WHERE search_date NOT BETWEEN start_date AND end_date;

Respondido 31 Jul 12, 11:07

Select *
from table
where [todaysdate]<datestart
or [todaysdate]>dateend

Respondido 31 Jul 12, 10:07

To select range you normally use BETWEEN, and if you want to exclude those values, you can simply use NOT BETWEEN.

Respondido 31 Jul 12, 10:07

Una variante más:

select id, start_date, end_date 
from my_table 
where end_date < CAST('2012-01-01' AS DATE) 
or start_date > CAST('2012-12-31' AS DATE)

Respondido 31 Jul 12, 11:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.