Board index » delphi » Tables -- How to Filter dates ?

Tables -- How to Filter dates ?

I am wondering about how to filter a TTABLE that has date fields..
The field name is "ADSTART" and if I put in for the filter,
ADSTART>04/11/96 , it says that "/" is an invalid filter character..
I've tried whole numbers, brackets around date, parenthasis, etc..
but no luck..

Any ideas ?
Please respond to
Richard.mo...@factory.com

Thanks!

 

Re:Tables -- How to Filter dates ?


Richard....

The Filter property of a TTABLE is a -string- type.
Your filter would be written as
      yourtable.Filter := 'ADSTART >'#39+'04/11/96'+#39;

Unclear? Ok, what you really want set in the Filter
property is a string that looks like what you'd set yourself
manually in the Filter property of the Object Inspector.

If you were setting it manually, you'd just type into the
property box       ADSTART > '04/11/96'
But this whole thing needs to be stored as a string,
single quote marks and all!
Notice that the string to be stored must have embedded '
characters in it.  That is the #39 in the solution above.
I find it easier to read that way.

If you wanted a "variable" filter, instead of always testing
for 04/11/96, say, because you have a date in a TDateTime variable
called  mydate, then you'd do something like....

      yourtable.Filter := 'ADSTART >'#39+DateToStr(mydate)+#39;

You activate and deactivate the filter by setting the
Filtered property to True or False.

John

Quote
Richard Morey wrote:

> I am wondering about how to filter a TTABLE that has date fields..
> The field name is "ADSTART" and if I put in for the filter,
> ADSTART>04/11/96 , it says that "/" is an invalid filter character..
> I've tried whole numbers, brackets around date, parenthasis, etc..
> but no luck..

> Any ideas ?
> Please respond to
> Richard.mo...@factory.com

> Thanks!

Re:Tables -- How to Filter dates ?


Try double slashes "4//11//96", are using BDE filters(which require SQL
type syntax, and do not require indices)? or are using the type in Delphi,
which I believe require .AsDate procedures?

Re:Tables -- How to Filter dates ?


Quote
Richard Morey <mail...@shpress.com> wrote:
>I am wondering about how to filter a TTABLE that has date fields..
>The field name is "ADSTART" and if I put in for the filter,
>ADSTART>04/11/96 , it says that "/" is an invalid filter character..
>I've tried whole numbers, brackets around date, parenthasis, etc..
>but no luck..
>Any ideas ?
>Please respond to
>Richard.mo...@factory.com
>Thanks!

I have tried working with dates in Delphi and found it to be very
frustrating.  However, I think I may be able to help.  Try using the
date as its integer equivalent (TDateTime is actually a real number
with the integer part representing the date and the decimal part
represents the time).  I use the DecodeDate and EncodeDate functions
to perform the conversion.  Give it a shot- if you continue to have
problems, mail me and I'll dig up some old source for you.

-Anthony

Other Threads