Search with date range [duplicate]

0

In MySQL I have a table that has two DATE fields: data_inicial and data_final .

In the System I have a Field (TextField) where I type a date.

This date does not need to be accurate, but rather matches the range.

Example:

  

Field Value: 2015-10-05

Values in the Table:

  

Start_Date | Date_Final:
  2014-12-18 2015-12-18
  2015-12-19 2016-12-19

My SQL:

SELECT Id, data_inicial, data_final, valor FROM periodos WHERE PasseioId = 1 and (data_inicial >= 2015-10-14 and data_final <= 2015-10-14)
    
asked by anonymous 05.10.2015 / 23:05

2 answers

0

Add quotes ' on dates data_inicial >= '2015-10-14' and data_final <= '2015-10-14'

    
05.10.2015 / 23:17
0

Using between :

SELECT Id, data_inicial, data_final, valor 
FROM periodos 
WHERE PasseioId = 1 
AND (data_inicial BETWEEN '2014-12-18' AND '2015-12-18')
    
05.10.2015 / 23:17