Well, as far as I know this is not possible, but you can go adding OR conditions in your code instead of IN, there would be more or less this way:
SELECT
*
FROM
Conteudo
WHERE
'2018-03-22' BETWEEN DATE(DataInicio) AND DATE(DataFim)
OR '2018-03-23' BETWEEN DATE(DataInicio) AND DATE(DataFim)
...
Follow example with tests:
CREATE TABLE teste_datas(
descricao VARCHAR(255),
data_inicio DATE,
data_fim DATE
);
INSERT INTO teste_datas(descricao, data_inicio, data_fim)
VALUES('desc 1', '2018-03-01', '2018-03-22'),
('desc 1', '2018-03-01', '2018-03-23'),
('desc 2', '2018-03-01', '2018-03-24'),
('desc 3', '2018-03-01', '2018-03-08'),
('desc 4', '2018-03-01', '2018-03-02');`
In case I run this query
:
SELECT
*
FROM teste_datas
WHERE '2018-03-22' BETWEEN data_inicio AND data_fim;
The result will be desc1, desc2 e desc3
because the date I’m looking for fits between the two periods
SELECT
*
FROM teste_datas
WHERE '2018-03-22' BETWEEN data_inicio AND data_fim
OR '2018-03-07' BETWEEN data_inicio AND data_fim;
if I add the OR
to query
will return to me desc1, desc2, desc3 e desc4
because the second date also fits a line.
If there is a date field, it really works that way, but if dates are entered manually, it wouldn’t work that way.
– arllondias
didn’t understand, @arllondias. There has to be a date field, otherwise you won’t have to check at the base
– rLinhares
It is not necessary one more field, thinks that it already has the fields that in the case of
query
of him he informs that he has theDataInicio
andDataFim
. If he puts a date in his hand and leaves so for example:WHERE '2018-03-22' BETWEEN DATE(DataInicio) AND DATE(DataFim)
He’s gonna bring me the records where the date fits between the dates he already has in the bank, you understand? exactly as I put in my answer there.– arllondias
@arllondias, got it. So your answer is correct :P
– rLinhares
I added a functional example in my reply =)
– arllondias