uses DateUtils;(*
function IncYear(const AValue: TDateTime;
  const ANumberOfYears: Integer = 1): TDateTime;
// function IncMonth is in SysUtils
function IncWeek(const AValue: TDateTime;
  const ANumberOfWeeks: Integer = 1): TDateTime;
function IncDay(const AValue: TDateTime;
  const ANumberOfDays: Integer = 1): TDateTime;
function IncHour(const AValue: TDateTime;
  const ANumberOfHours: Int64 = 1): TDateTime;
function IncMinute(const AValue: TDateTime;
  const ANumberOfMinutes: Int64 = 1): TDateTime;
function IncSecond(const AValue: TDateTime;
  const ANumberOfSeconds: Int64 = 1): TDateTime;
function IncMilliSecond(const AValue: TDateTime;
  const ANumberOfMilliSeconds: Int64 = 1): TDateTime;
*)

解决方案 »

  1.   

    呵呵,用它吧:
    function IncMonth(const Date: TDateTime; NumberOfMonths: Integer): TDateTime;
      

  2.   

    Y,M,D: Word;
    DecodeData(aDate, Y, M, D);
    M:=M+dM;
    Y:=Y+ (M+11) div 12 - 1;
    M:=(M+11) mod 12 -1;
    Result := EncodeDate(Y,M,D);
      

  3.   

    //for Delphi6procedure TForm1.Button2Click(Sender: TObject);
    begin
      ShowMessage(DateToStr(IncMonth(StrToDate('2002-01-20'), 6)));
      ShowMessage(DateToStr(IncMonth(StrToDate('2002-01-20'), 18)));
      ShowMessage(DateToStr(IncMonth(StrToDate('2002-01-20'), -6))); //不要忘记还可以这样
    end;
      

  4.   

    好办法没有,倒是有一个笨办法.
    用DecodeDate 把年份和月份分离出来,把月分相加,然后再用 mod函数 求得
    月份 mod 12 余数就是所求月份,用 div 求得除数,这里要使用到trunc函数.
    除数就是要加的年份,然后用encodedatE就可以全成新的日期了.
      

  5.   

    呵呵,其实也可以这样嘛:
    你用sql语句来加月份,这样就不用你考虑什么二月怎么办,30天的月和31天的月怎么办,闰年怎么办之类的问题,举个例子:...
    query_test.close;
    query_test.sql.clear;
    query_test.sql.add('values(date('2002-4-3')+6 month)');
    query_test.open;
    showmessage(query_test.fields[0].asstring);
    query_test.close;
    ...
      

  6.   

    嗯?
    好久不来csdn了,现在怎么多了一些五角星和三角?是什么东东?还有,上面的query_test.sql.add('values(date('2002-4-3')+6 month)');
    应该写成query_test.sql.add('values(date(''2002-4-3'')+6 month)');
    刚才没注意,给写错了
      

  7.   

    to bob7946:制片大人,你没有看看csdn的help吗?嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻
    嘻嘻嘻嘻好久不见嘻嘻嘻嘻嘻
    嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻
      

  8.   

    delphi中日期+1代表1天,即2002-04-10 +1 =2002-04-11
    日期其实是一个double类型,整数部分代表日期,小数部分代表时间,
      

  9.   

    就是,时间就是一个double 
    想加一个月,就加30
    管他一个月几天?!