I am creating a module in a system with PHP and MySQL, where I am making an agenda for events. I have a table with the following fields:
-
id_evento
-
nombre_evento
-
fechaInicial
-
fechaFinal
-
id_ubicacion
In the creation form for the agenda, the user has two input
of type date
, where he enters the initial date and the final date of his event, suppose that I have registered an event with fechaIncial = '2016-02-18'
and fechaFinal = '2016-02-22'
.
If the user enters fechaIncial = '2016-02-19'
and fechaFinal = '2016-02-19'
as valid it is already registered an event between 18 and 22, which is where it would enter on the 19th.
I currently have this query but I'm not sure how it works because it only validates me OR
SELECT id_evento,nombre_evento,id_ex_ubicacion,fecha_ini_evt,fecha_fin_evt,hora_ini_evt,hora_fin_evt
FROM eventos
WHERE fecha_ini_evt >= '2016-02-19'
AND fecha_fin_evt <= '2016-02-19'
OR fecha_fin_evt BETWEEN '2016-02-19' AND '2016-02-19'
OR fecha_ini_evt BETWEEN '2016-02-19' AND '2016-02-19'
AND id_ex_ubicacion = 1