Range of dates in another date range

0

I have two columns of type DATETIME : one is called dataHoraSaida and another dataHoraRetorno in a table called trip. I would like to enter with two dates (a break) and know if there is any record already in that date range. Example: I would like to know if there is already a record in the 2017-01-01 00:00:00 2017: 01-09 00:00:00 range.

Thank you very much!

    
asked by anonymous 10.04.2017 / 08:04

2 answers

0

To do this, mount your sql this way if you want to compare only the date:

SELECT * FROM 'viagem' WHERE cast(dataHoraSaidaas DATE) >= '2017-04-10' and cast(dataHoraRetorno DATE) <= '2017-04-15' 

If you want to compare date and time:

SELECT * FROM 'viagem' WHERE dataHoraSaidaas >= '2017-04-05 00:00:00' and dataHoraRetorno <= '2017-04-15 00:00:00'
    
10.04.2017 / 13:10
0

If I get it right, what you want is this:

SELECT *
FROM 'viagem'
WHERE dataHoraSaida > '2017-01-01 00:00:00' AND dataHoraRetorno < '2017:01-09 00:00:00'
    
10.04.2017 / 13:09