我现在有一个差值(整型的),还有一个日期型的(当天的日期),我想得到今天的日期加上这个差值以后的日期。怎么实现?我得到的总是2003-10-31 1:0:0!!!!(其中的1是我得到的差值)

解决方案 »

  1.   

    先DecodeDate()后加上差值
     再EncodeDate(Year, Month, Day: Word): TDateTime;
      

  2.   

    var
      date:TDateTime;
    begin
      date := now + 1;
      showmessage(datetimetostr(date));
    end;
      

  3.   

    给你贴段delphi的代码
    procedure TForm1.Button1Click(Sender: TObject);var
      Present: TDateTime;
      Year, Month, Day, Hour, Min, Sec, MSec: Word;
     begin
      Present:= Now;
      DecodeDate(Present, Year, Month, Day);
      Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
        + IntToStr(Month) + ' of Year ' + IntToStr(Year);
      DecodeTime(Present, Hour, Min, Sec, MSec);
      Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
        + IntToStr(Hour);
    end;
    运行一下你就知道decodedate的作用了,然后可以根据你的要求在上面加上差值了,如果还要时间的话就用DecodeDateTime(const AValue: TDateTime; out AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond: Word);
    这是encodedate的例子
    rocedure TForm1.Button1Click(Sender: TObject);var
      MyDate: TDateTime;
    begin
      MyDate := EncodeDate(StrToInt(Edit1.Text), StrToInt(Edit2.Text), StrToInt(Edit3.Text));
      Label1.Caption := DateToStr(MyDate);
    end;
    应该能明白了吧
      

  4.   

    showmessage(datetimetostr(date + 1)); 
    根本没你说的现象