请教:
我使用:select * from 主表 where 日期=now,结果集为空,
检查发现access的日期字段是使用日期和时间格式如2003-12-20 11:00:00,
因此我得到的结果当然是空的,
如何使用SQL使我能得到日期为今天的所有记录?

解决方案 »

  1.   

    getdate()这个函数获得的好像还是有时间的数据的
    所以产旬的时候很可能是还是没有结果的 说的不一定对的啊
    你可以在delphi完成日期的转化的
    StrtoDateTime(FormatDateTime('yyyy-mm-dd', Now()))获得当前的没有时间的日期的
    然后再sql中利用参数来实现的
      

  2.   

    你把当前日期format一下,format成数据库的那种日期格式.
      

  3.   

    SELECT CONVERT(CHAR,getdate(),101) 这样就可以在sql里面获得当前的没有时间的日期了
      

  4.   

    我的主表记录中的日期是带时间格式的,以前我是用:
    adoQuery.sql.add('select * from 主表 where 日期 between date1 and date2');
    decodeDatetim(now,year,month,day,hour,minute,second,msecond)
    date1 :=encodeDatetime(year,month,day,00,00,00,00)
    date2 :=encodeDatetime(year,month,day,23,59,59,999)
    adoQuery.parameters.fieldByName('date1').value :=date1;
    adoQuery.parameters.fieldByName('date2').value :=date2;
    adoQuery.open;  
    来得到结果集的,发现比较罗嗦,想知道更简单的时间判断方法。另外我的access不运行在sql server下。
    请教大侠高见!
      

  5.   

    关注!
    也想知道关于这方面的东西特别是ADOQuery的知识
      

  6.   

    主要看你的后台数据库是什么,如果是Access:
    select * from 主表 where 日期=#2003-12-22#
    如果是SQl:
    select * from 主表 where 日期='2003-12-22'
    由上可以看到它们的日期格式是不一样
      

  7.   

    ///////////////////////////////////////////////////////////////////////
    楼上说的是固定的日期的时候的SQL表达式,如果是变化的话,你在Delphi中可以这样写:
    ADOQuery.Add('select * from 主表 where 日期='+DateToStr(Today()));
    //其中Today是取当前日期函数,这个函数需要引用DateUtils单元
    //////////////////////////////////////////////////////////////////////
      

  8.   

    有些数据库不支持getdate,就用delphi获取当前时间,然后查询
      

  9.   

    select * from 主表 where 日期='#'+formatDatetime('yyyy-mm-dd hh:mm:ss',now)+'#';
      

  10.   

    select * from 主表 where datediff(day,日期, getdate()) = 0
      

  11.   

    select * from 主表 where 日期='#'+FormatDateTime('yyyy-mm-dd hh:mm:ss',now)+'#';
      

  12.   

    select * from 主表 where 日期>=date() and 日期<=date()+1
      

  13.   

    temp_time:=StrtoDateTime(FormatDateTime('yyyy-mm-dd', Now));
    select * from 主表 where 日期='#'+temp_time+'#';
      

  14.   

    to 小别:您的方法解决了我的大问题。我只知其一(now)不知其二(date())。
    非常感谢!