1
I need a light for a question, I have a data filtering system (search) where I have to search for two Initial and Final dates. Since I have these two columns in the database, then when I run the search I choose which column I want to filter. Both columns are of the type date
Then my sql got more or less like this:
SELECT * FROM negocio WHERE data_inicial BETWEEN '2017-01-01' AND '2017-01-30' ORDER BY data_inicial DESC
However in the results it does not only return dates within the selected period, for example it returns date data 2017-02-20
and empty field that does not yet have its date set.
CREATE TABLE negocio (
negocio_id int(11) NOT NULL auto_increment,
data_inicial date default NULL,
data_final date default NULL,
PRIMARY KEY (negocio_id)
);
As I said are the fields, but the question is to return the dates within the period selected by the user. In case the user can select whether to search in data_inicial
or data_final
and in which order he would like to display the data.
The query you use is the same as the question?
– rray
Your dates are saved with hours:minutes:seconds in the bank or not?
– Jeferson Almeida
Can you paste the table structure here? Sometimes it’s a field with a different name.
– William Aparecido Brandino
The query is in a period of 30 days as corrected in question :( I will post the table below
– Helison Santos
The date
2017-02-20
is the column being filtered? If chosendata_inicial
then that date is coming in this field?– Ismael
Yes the date
2017-02-20
is in the same filtered column. Correct returning the date in this field.– Helison Santos