如何单位取得系统时间的年月日?我还有一个问题请教:那就是我操作access数据库
的时候,我有一个字段是时间型的,但我利用这个字段查询东西的时候,怎么也查不到东西。
q1.SQL.Add('select sum(money) as aa from moneyin where time>'+(year1.Text+'-'+month1.Text+'-'+day1.Text)+' and time<'+(year2.Text+'-'+month2.Text+'-'+day2.Text));我的语句是这样写的其中year1.Text+'-'+month1.Text+'-'+day1.Text和year2.Text+'-'+month2.Text+'-'+day2.Text分别组成了个时间,与数据库中time存储的格式是一样的。我想让这个语句查到东西!请指教!

解决方案 »

  1.   

    var
     Y, M, D: Word;DecodeDate(Date, Y, M, D);
      

  2.   

    Access的分隔符应该不是',可能应该是#吧。
      

  3.   

    同意楼上的,还有的方法就是引入date单元(好像是这个单元,记不清楚了)里面有三个函数
    专门得到年月日,还有时分秒的
      

  4.   

    function  GetYear(D: TDateTime): Integer;
    var
      Year,Month,Day : Word;
    begin
      DecodeDate(D,Year,Month,Day);
      Result:=Year;
    end;function  GetMonth(D: TDateTime): Integer;
    var
      Year,Month,Day : Word;
    begin
      DecodeDate(D,Year,Month,Day);
      Result:=Month;
    end;function  GetDay(D: TDateTime): Integer;
    var
      Year,Month,Day : Word;
    begin
      DecodeDate(D,Year,Month,Day);
      Result:=Day;
    end;
      

  5.   

    var
        ss: TDateTime;
        CYear, Cmonth, CDate: word;
        MAX: integer;
    begin
        ss := now;
        decodedate(ss, cyear, Cmonth, CDate);
      

  6.   

    q1.SQL.Add('select sum(money) as aa from moneyin where time between date('+year1.Text+','+month1.Text+','+day1.Text + ) and  date('+year2.Text+','+month2.Text+','+day2.Text + ')');
      

  7.   

    q1.SQL.Add('select sum(money) as aa from moneyin where time>'''+(year1.Text+'-'+month1.Text+'-'+day1.Text)+''' and time<'''+(year2.Text+'-'+month2.Text+'-'+day2.Text)+'''');
      

  8.   

    q1.SQL.Add('select sum(money) as aa from moneyin where time>#'+(year1.Text+'-'+month1.Text+'-'+day1.Text)+'# and time<#'+(year2.Text+'-'+month2.Text+'-'+day2.Text + '#'));
    access数据库查询时间类型的应该用'#'将时间引起来。