你想直接读paradox吗? 最好的办法还是用SQL
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('Select * from Table1 where 日期字段1 between :ADate and :BDate');
Query1.Params[0].AsDate = StrToInt(Edit1.Text);
Query1.Params[2].AsDate = StrToInt(Edit2.Text);
Query1.Prepare;
Query1.Open;
end;
1、查询具体日期,例如
select * from people.db where birthday>="6/19/1999"
即日期型表示须为月/日/年
2、查询年、月、日之类
select * from people.db where extract(year from birthdate)="1999"
select * from people.db where extract(month from birthdate)="6"
假如你的查询参数是可变的,即日期不固定,那么需要编个函数来件日期转为上文所
说的格式,可以这样:
//转换日期函数
function mydatetostr(indate: tdate): string;
var
year, month, day: word;
begin
decodedate(indate, year, month, day);
result :='"'+ inttostr(month) + '/' + inttostr(day) + '/' +
inttostr(year)+'"';
end;
//获取转换年的函数
function mygetyeartostr(indate: tdate): string;
var
year, month, day: word;
begin
decodedate(indate, year, month, day);
result := inttostr(year);
end;
1、假设要比较的日期由datetimepicker给出,则查询语句可以这样:
with query1 do
begin
close;
sql.Clear;
sql.Add('select * from people.db where birthdate>='+
mydatetostr(datetimepicker1.date));
open;
end;
2、假设要比较的年份由datetimepicker的年份给出,则查询语句可以这样:
with query1 do
begin
close;
sql.Clear;
sql.Add('select * from people.db where
extract(year from birthdate)>='+
mygetyeartostr(datetimepicker1.date));
open;
end;