Board index » delphi » How to Filter a Date on a table

How to Filter a Date on a table

Hello everyone,
I would like to use Table.Filter for a date field.
Lets say that Table1 has two fields: Code as String; Da{*word*249}ter as TDate;
I learned that I can do this with String, and it works
With Table1 Do
  Begin
     Filtered := False;
     Filter     := 'Code = '  +  #39  +  'Food*' +  #39 // It looks for all
Foods, or food1,or food.... Etc.
    Filtered := True;
  End;
However, I do not know how to do that on a date field. Please help
As I had tried:
Lets say I would like to show only all record in the month of August 1999
  or another word (Da{*word*249}ter BETWEEN '08/01/1999' AND '08/31/1999'
Var  DateE : String;
 DateE := '08*';
With Table1 Do
  Begin
     Filtered := False;
     Filter     := 'Da{*word*249}ter = ' +  #39 + DateE + #39;
    Filtered := True;
  End;
I did not work because the Date field.

Please don't mind to help me with a few codes

Thanks you all inadvance

Sincerely yours

Tin Le

 

Re:How to Filter a Date on a table


Quote
On Wed, 1 Sep 1999 13:44:05 -0700, "Tin Le" <tin...@mhhs.org> wrote:

[...]

Quote
>Var  DateE : String;
> DateE := '08*';
>With Table1 Do
>  Begin
>     Filtered := False;
>     Filter     := 'Da{*word*249}ter = ' +  #39 + DateE + #39;
>    Filtered := True;
>  End;

[...]

Wildcard characters in the Filter property only work for String fields. To
do what you need with this data field, my suggestions are:

1. Use the >= and <= operators to make two comparisons between the field
and the dates 08/01/1999 and 08/31/1999.

2. Use the QuotedStr function to embed the quotation marks to delimit the
date literals.

  with Table1 do begin
    Filtered := False;
    Filter := 'Da{*word*249}ter >= ' QuotedStr('08/01/1999') + ' AND ' +
      'Da{*word*249}ter <= ' QuotedStr('08/31/1999')
    Filtered := True;
  end;

If the comparison values must be dynamic, build them as strings outside
this code and use two variables for the dates, one each for the starting
and ending dates of this range.

==========================================================================
Steve Koterski                  "Computers are useless. They can only give
Technical Publications          you answers."
Borland                                       -- Pablo Picasso (1881-1973)
http://www.borland.com/techpubs/delphi

Re:How to Filter a Date on a table


Good morning Steve Koterski ,
I have left your messages here for someone else might have take a snapshot.
Is that easy? I have not think about that logic because I always put my
focus
on the * or % instead of >= or <= logic.
Your answer make sense since I am a chess player and you are the third
person
see things more clear than the players.

Thanks you very much, and may God blesses you and everyone.

Best regard

Tin Le

Quote
>Wildcard characters in the Filter property only work for String fields. To
>do what you need with this data field, my suggestions are:
>1. Use the >= and <= operators to make two comparisons between the field
>and the dates 08/01/1999 and 08/31/1999.
>2. Use the QuotedStr function to embed the quotation marks to delimit the
>date literals.
>  with Table1 do begin
>    Filtered := False;
>    Filter := 'Da{*word*249}ter >= ' QuotedStr('08/01/1999') + ' AND ' +
>      'Da{*word*249}ter <= ' QuotedStr('08/31/1999')
>    Filtered := True;
>  end;
>If the comparison values must be dynamic, build them as strings outside
>this code and use two variables for the dates, one each for the starting
>and ending dates of this range.

Other Threads