DateTimePicker.data转换成string
var
s1,s2:string;
s1:=datetimetostr(DateTimePicker1.data);
s2:=datetimetostr(DateTimePicker2.data);
adoquery1.sql.add('select * from table where f_data >'''+s1+''' and f_data<'''+s2+''' ';
try
with ADOQuery1 do
begin
if Active then Active:=False;
SQL.Clear;
SQL.Add('SELECT * FROM TABLENAME');
SQL.Add('Where Date>=:A and Date<=:B');
Prepared;
Parameters.ParamByName('A').Value:=DateTimePicker1.DateTime;
Parameters.ParamByName('B').Value:=DateTimePicker2.DateTime;
Active:=True;
end;
except
ShowMessage('无法打开数据集!',0);
end;
Var
S1,S2:String;
Begin
S1:=DatetimeToStr(DateTimePicker1.Data);
S2:=DatetimeToStr(DateTimePicker2.Data);
AdoQuery1.SQL.Add('SELECT * FROM TABLE WHERE f_data BETWEEN ''' + S1 + ''' AND '''+ S2 +'''';
End;
我前几天也遇到了这样的问题,我感觉用decodedate最简单了
var
year,month,dd:word;
begin
decodedate(DateTimePicker1.Date,year,month,dd)
adoquery.sql.add('select * from table where year(填报时间)='''+inttostr(year)+''' and month(填报时间)='''+inttostr(month)+'''')