1、数据表中字段 publishedtime记录了信息的发布时间。(Access表)如何得到 所有的,今天发布的信息? 在SQLSERVER2000中,下面写法是对的。如果数据表是ACCESS,就不知如何改了?sql = "select * from systemdata where (DATEDIFF(dd, publishedtime, GETDATE()) = 0) order by id desc"我试着写: thisdate:= Date();
todayado.SQL.Text:='Select * From systemdata where (DATEDIFF(dd, publishtime, thisdate) = 0) order by id ';不行。
===========================2、如果 用户根据 DateTimePicker控件选择了两个日期段,如何用SQL语句,输出所有的,这个日期段内的记录啊?(数据表分别是SQLSERVER和ACCESS)
SQL=' select * from systemdata where 日期1 到 日期2 '谢谢!
todayado.SQL.Text:='Select * From systemdata where (DATEDIFF(dd, publishtime, thisdate) = 0) order by id ';不行。
===========================2、如果 用户根据 DateTimePicker控件选择了两个日期段,如何用SQL语句,输出所有的,这个日期段内的记录啊?(数据表分别是SQLSERVER和ACCESS)
SQL=' select * from systemdata where 日期1 到 日期2 '谢谢!
2.sql : SELECT * from systemdata where publishtime between '2008-1-1' and '2008-1-1 23:59:59'
access : SELECT * from systemdata where publishtime between #2008-1-1# and #2008-1-2#
todayado.sql.clear;
todayado.SQL.add('Select * From systemdata where publishtime>=:date1 and publishtime <=:date2 order by id')
todayado.Parameters.Items[0].Value:=Date1.DateTime;
todayado.Parameters.Items[1].Value:=Date2.DateTime;
todayado.open
用这种方法你以上提的两种问题都可以实现,如果是当天就是date1的date2都是当天,这种方法在access下测试ok
todayado.sql.close;
todayado.sql.clear;
todayado.SQL.add('Select * From systemdata where publishtime>=:date1 and publishtime <=:date2 order by id')
todayado.Parameters.Items[0].Value:=Date1.DateTime;
todayado.Parameters.Items[1].Value:=Date2.DateTime;
todayado.open;
todayado.Parameters.Items[0].Value:= temptoday;
todayado.Parameters.Items[1].Value:= temptoday;
todayado.Open; //执行sql 返回结果,要用.open我这样写了,但按提示: 标准表达式中数据类型不匹配
Form2: TForm2;
temptoday:TDate;
temptoday:=Date(); //获取当前日期