Question : Delphi 'LIKE' DateTime filter

I can't believe I can't remember how to do this (it's been a while!)

I have a datetime field and my users want to just see everything entered by the year.  There is of course a Month/Day/Year in the field.  So I simply need a filter like this:

Expiration LIKE '*/2012'

or whatever this might take to just filter everything for 2012 : or whatever year the user enters.

Answer : Delphi 'LIKE' DateTime filter

Using the dataset filter property will not work as you want since it doesn't accept LIKE.

You could use a TQuery component and set its SQL property to this:

select * from Table
where Expiration like '%/' + :YEAR

In your form, you should add this code:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Query1.Close;
  Query1.ParamByName('YEAR').AsString := Edit1.Text;
  Query1.Open;
end;
Random Solutions  
 
programming4us programming4us