Board index » delphi » How can I specify the Dataset.Filter with DATE field ?

How can I specify the Dataset.Filter with DATE field ?

Hi,

I am a new D6 developer.  I code the following statement in DataSet.Filter
in DataSetBeforeOpen event procedure.

  Query1.Filtered := False;
  Query1.Filter   := 'Query1DATE.AsString >= ' +
                      DateTimeToStr(dFmDate) + ' AND ' +
                      'Query1DATE.AsString <= ' +
                      DateTimeToStr(dToDate);
  Query1.Filtered := True;

It will cause a run-time error message "Arguments are of the wrong type, are
out of acceptable range, or are in conflict with one another".
As the reason of program design, I will not code the above condition in
DataSet.SQL statement.

Would you give me your advice ?  Thank you for your reply in advance !!!

Regards,
Nelson.

 

Re:How can I specify the Dataset.Filter with DATE field ?


Quote
nelson chui wrote:

>   Query1.Filter   := 'Query1DATE.AsString >= ' +
>                       DateTimeToStr(dFmDate) + ' AND ' +
>                       'Query1DATE.AsString <= ' +
>                       DateTimeToStr(dToDate);

Try to change it into:

Query1.Filter   := '(MYDATEFIELD >= ' +
    QuotedStr(FormatDateTime('mm/dd/yyyy',dFmDate))+
    ') AND (MYDATEFIELD <= ' +
   QuotedStr(FormatDateTime('mm/dd/yyyy',dToDate))+ ')';

HTH,

-Jaimy

Re:How can I specify the Dataset.Filter with DATE field ?


Quote
Alan McDonald wrote:

> if you want to get complicated with your filters use the onFilter event
it's
> a lot more flexible

but there is a trade-off since filtering is executed on the client-side.
unless the query resulting a large amount of data, perhaps this side-effect
would not be a problem.

-Jaimy

Re:How can I specify the Dataset.Filter with DATE field ?


certainly the best "filter" is a good piece of SQL
Alan
Quote
"Jaimy Azle" <ja...@nospam.sat.net.id> wrote in message

news:3d8ac8b0@newsgroups.borland.com...
Quote
> Alan McDonald wrote:

> > if you want to get complicated with your filters use the onFilter event
> it's
> > a lot more flexible

> but there is a trade-off since filtering is executed on the client-side.
> unless the query resulting a large amount of data, perhaps this
side-effect
> would not be a problem.

> -Jaimy

Other Threads