那位大侠能指点一下,有没有函数能计算出当前日期加上 x 后的日期?

解决方案 »

  1.   

    uses DateUtils单元,该单元中应该有你要的函数:我的版本是delphi6
    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;
      

  2.   

    如果a日期和b日期相加,则可以直接进行: a + b //新日期
      

  3.   

    本身日期就为double所以可以直接加的
      

  4.   

    sqlserver中有这样的函数,例如:dateadd(day,21,2002-1-1)表示2001-1-1加上21天后的日期,dateadd(month,2,2002-1-1)表示2001-1-1加上2个月之后的日期,dateadd(year,1,2002-1-1)表示2001-1-1加上1年之后的日期,dateadd(week,3,2002-1-1)表示2001-1-1加上3周之后的日期。
      

  5.   

    sorry,以上的2001-1-1都应改为2002-1-1。纯属笔误!
      

  6.   

    同意tootwoto说法,方法简单实用,参考一下你的delphi里有dateutil.pas单元。
      

  7.   

    二楼的正确,使用DateUtils单元的日期函数,很方便。如果只是求x日后的日期,直接加天数就可以了。
      

  8.   

    我收到你的留言了,看这个例子。var
       MyDate : TDateTime;begin   MyDate := NOW + 5;  //5天后的日期,NOW返回当天的日期
    另外一种用法,必须要在主程序中增加
    Uses DateUtils;  //增加时按格式写在后面就行,不用Uses的。var
       MyDate : TDateTime;begin   MyDate := IncDay(NOW,5);  //5天后的日期,IncDay是DateUtils函数,主程序                 单元必须引用现在应该清楚的吧。