Board index » delphi » Filter on a date

Filter on a date

I need to set a complicated filter using a date field. I cannot perform
this action using a setrange because there are 6 additional conditions
in this filter.

        All conditions in the filter work except dates. The date data is being
rejected and produces a message that the filter cannot accept a '/' as
input. Can anybody help me filter on date fields ??? Do I need to
convert the date to an absolute numeric value and the turn that value
into a string ??? My code is below. Thank you.

        My attempt was as follows:

        var BegDate, EndDate :TDateTime;  // Set by user input

        begin

           TBDeal.Filter:='TrDate'+'>='+DatetoStr(BegDate)+' AND
'+'TrDate'+'<='+DatetoStr(EndDate)+"Other Filter Items ,etc."

         end;

 

Re:Filter on a date


I did something like this on the Orders table in the DBDEMOS that come with
Delphi and it worked fine:

Table1.Filtered := False;
   Table1.Filter := 'saledate >= ' +  QuotedStr(edit1.text) +
       ' and shipdate <= ' + QuotedStr(Edit2.text) +
       ' and custno = ' + Edit3.text;
   Table1.Filtered := True;

--
Michael Glatz
mgl...@briefcase.com

Quote
nhuhta wrote in message <3606B5BA.4...@digital.net>...
>I need to set a complicated filter using a date field. I cannot perform
>this action using a setrange because there are 6 additional conditions
>in this filter.

> All conditions in the filter work except dates. The date data is being
>rejected and produces a message that the filter cannot accept a '/' as
>input. Can anybody help me filter on date fields ??? Do I need to
>convert the date to an absolute numeric value and the turn that value
>into a string ??? My code is below. Thank you.

> My attempt was as follows:

> var BegDate, EndDate :TDateTime;  // Set by user input

>        begin

>    TBDeal.Filter:='TrDate'+'>='+DatetoStr(BegDate)+' AND
>'+'TrDate'+'<='+DatetoStr(EndDate)+"Other Filter Items ,etc."

>         end;

Re:Filter on a date


Dates must be in quotation marks. For example:

SaleDate > '7/1/88'

works with the sample Orders table.  If you are storing the date in a
variable the QuotedStr function provides an easy way to add the quotes. For
example:

S := '7/1/88';
Table1.Filter := QuotedStr(S);
Table1.Filtered := True;

--
Bill Todd
(Sorry but TeamB cannot answer questions received via email)
(Remove nospam from my email address to contact me for any other reason)

Other Threads