Query sql does not work with date in Delphi

Asked

Viewed 1,286 times

1

I am making the following query in Delphi, using Mysql:

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

Does not return anything in Delphi, if I run the following query in Mysql:

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

How can I fix this?

Abs

  • People, already solved, was like this: Queryextraidados.Close; Queryextraidados.SQL.Clear; Queryextraidados.SQL.Add('Select * from customers Where nascimento='+Quotedstr(antecedence)+' '); Queryextraidados.Open;

  • Renato, please post your solution as an answer, not a comment. And since you already solved the problem, accept one of the answers as the solution to your question. It may be your own. If other answers have helped you, vote for them by clicking the up arrow, so you encourage the good answers. Hug!

2 answers

3

In accordance with 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 to say:

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

Thus the correct way of the SQL statement would be:

select * from clientes where nascimento = '2015-05-26' 

3

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’t remember if it is Params, ParamByName, but just try and make it work, just one detail the antecedence variable has to be like TDate or TDateTime.

Browser other questions tagged

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