How can I filter with dates in my adoquery dataset?

hidrau
hidrau used Ask the Experts™
on
I tried this and nothing

  QServerXML1.Filter   := 'SV1_DATAHORA=#16/03/2012#';
  QServerXML1.Filtered := tRUE
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Geert GOracle dba
Top Expert 2009

Commented:
have you tried like solution in this Q ?
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21441584.html

uses DateUtils;

QServerXML1.filter := 'OrderDate=' + FloatToStr(EncodeDate(2012,03,16));
Commented:
Are you using the right date format in your filter conditon?

Try ShowMessage(DateToStr(QServerXML1.FieldByName('SV1_DATAHORA').AsDateTime))

Check if date format really is dd/mm/yyyy...
Geert GOracle dba
Top Expert 2009

Commented:
offtopic> Thommy
are you trying to beat my score overal or just this year ?

nothing really new in your last response

Commented:
Sorry Geert, don't wanna chase your score!!!

I should have been reading your EE link before posting my answer.
It clearly says what I meant...
Commented:
Geert_Gruwez

I tried and it doesn't work.

I get an exception when I try to pass this:

  QServerXML1.filter   := 'SV1_DATAHORA=' + FloatToStr(EncodeDate(2012,03,16));

it seems that this is not supported
Geert GOracle dba
Top Expert 2009

Commented:
>>hidrau
what is the exception msg ?

>>Thommy
I was only joking, no need to apologize

i'd check further along Thommy's comments for Date format

> check your environment settings
> have you set a default in your delphi environment ?
> what type of database is it ?
> what date type and date type input does it expect for the filter

Author

Commented:
My Database is MS SQL 2005

The field is datetime.
Oracle dba
Top Expert 2009
Commented:
try it with convert

  QServerXML1.filter   := 'SV1_DATAHORA=CONVERT(Date, "16/03/2012", 101)';

or with double single quotes

  QServerXML1.filter   := 'SV1_DATAHORA=CONVERT(Date, ''16/03/2012'', 101)';

Author

Commented:
Delphi gave me the following message: incorrect arguments

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial