Search with date range

Asked

Viewed 230 times

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 precise, but corresponds to the range.

Example:

Field Value: 2015-10-05

Values in the Table:

Initialdata_ | 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)

2 answers

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')
  • Search comes empty

  • Did you perform the search using the example in datetime format? Tried using date only? I formatted the answer

0

Quote ' on the dates data_inicial >= '2015-10-14' and data_final <= '2015-10-14'

  • 1

    It only brings line two. more does not check, because the initial date of line two is 2015-12-19 and my search is 2015-10-14.

Browser other questions tagged

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