Reputation: 99
So, I have a Query: "Select * FROM Payments WHERE Day([PayDate])=Day(Date()) AND Month([PayDate])=Month(Date())"
And I was wondering how can I do this in the ADOQuery.Filter
propertie of the ADOQuery.
I know you can use "Ands" to put more than one condition, but I don't get the Month(Date())
and Day(Date())
thing in this.
I'm using an Access database btw.
Upvotes: 1
Views: 779
Reputation: 164
ADOQuery.Filter is not the same as SQL "WHERE" clause.
You need to calculate functions in SQL before using them.
Try to make like this:
ADOQuery.SQL.Text := 'SELECT *, Day([PayDate]) AS d, Month([PayDate]) AS m FROM Payments';
And then use "d" and "m" fields in ADOQuery.Filter
uses DateUtils;
procedure FilterQuery;
var
D: TDateTime;
begin
D := Now;
ADOQuery.Filtered := False;
ADOQuery.Filter := Format('d = %u AND m = %u', [DayOf(D), MonthOf(D)]);
ADOQuery.Filtered := True;
end;
Upvotes: 1