sql query does not work with date in Delphi

0

I'm doing the following query in Delphi, using MySQL:

QueryExtraiDados.Close;
QueryExtraiDados.SQL.Clear;
QueryExtraiDados.SQL.Add('Select * from clientes where nascimento='+QuotedStr('%'+antecedencia+'%')+' ');
QueryExtraiDados.Open;      

It does not return anything to me in Delphi, if I run the following query in MySQL:

Select * from clientes where nascimento='2015/05/26'

How can I resolve this?

Abs

    
asked by anonymous 14.05.2015 / 15:27

2 answers

2
QueryExtraiDados.Close;
QueryExtraiDados.SQL.Clear;

QueryExtraiDados.SQL.Add('Select * from clientes where    nascimento=:dtNasc');
QueryExtraiDados.Params[0].Value := FormatDateTime('yyyy-mm-dd', antecedencia);
QueryExtraiDados.Open; 

I just can not remember if it is Params , ParamByName , but just try to do it right, just a detail the variable antecedence has to be TDate or TDateTime type.

    
14.05.2015 / 23:23
2

As per described in the mysql manual second paragraph:

  

The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'.

That is:

MySQL retrieves and displays DATE values in yyyy-mm-dd format. The supported range is 1000-01-01 to 9999-12-31 .

In this way the correct way of the SQL statement would be:

select * from clientes where nascimento = '2015-05-26' 
    
14.05.2015 / 23:17