Date range in other date range

Asked

Viewed 51 times

0

I have two columns of the kind DATETIME: one is called dateHoraSaida and another dateHoraReturn into a table called trip. I would like to enter two dates (a break) and know if there is already any record in this range of dates. Example: I wonder if in the range 2017-01-01 00:00:00 2017:01-09 00:00:00 there is already some record.

Thank you very much!

2 answers

0

If I understand correctly, what you want is this:

SELECT *
FROM `viagem`
WHERE dataHoraSaida > '2017-01-01 00:00:00' AND dataHoraRetorno < '2017:01-09 00:00:00'
  • Edit your response by guiding operator usage BETWEEN.

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'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.