t5:=' 1=1 ';
if CheckBox5.Checked then
t5:=' 生日>=#'+DateToStr(DateTimePicker1.Date)+'# and 生日<=#'+DateToStr(DateTimePicker2.Date)+'#';
if CheckBox5.Checked then
t5:=' 生日>=#'+DateToStr(DateTimePicker1.Date)+'# and 生日<=#'+DateToStr(DateTimePicker2.Date)+'#';
建议你用参数就可以解决这个问题,时间用参数标识,在打开数据集的之前用ParaByName('时间参数1').Value:=TDateTime变量即可,这样可以避免不同的数据库的时间表示法和界定符不同的问题如果是oracle的话,可以用to_date函数方便明确的转换,达到在sql语句中硬编码
例如:select * from 表1 where 时间字段1 >= to_date('19900101','yyyyMMdd')
数据库不同SQL语句略有不同。
t5:=' 生日>=#'+formatdatetime('yyyy-mm-dd',DateTimePicker1.Date)+'# and 生日<=#'+formatdatetime('yyyy-mm-dd',DateTimePicker2.Date)+'#';
t5:=' 生日>=#'+formatdatetime('yyyy-mm-dd',DateTimePicker1.Date)+'# and 生日<=#'+formatdatetime('yyyy-mm-dd',DateTimePicker2.Date)+'#';
如果是mssql那么t5:=' 生日>='''+formatdatetime('yyyy-mm-dd',DateTimePicker1.Date)+''' and 生日<='''+formatdatetime('yyyy-mm-dd',DateTimePicker2.Date)+'''';