已知现在的日期,我想得到1个月之后的日期,或者几个月之后的日期,应该怎么换算。即已知现在为2003-07-17,我要得到1个月之后即为2003-08-17;还有就是如果我要得到7个月之后的那应该是2004-02-17,这个应该怎么换算得到啊。请高手指教。多谢!

解决方案 »

  1.   

    记错了,好像是
    YourDate := IncMonth(Date, 7);
      

  2.   

    to chechy
    能够给我举个简单的例子吗?
      

  3.   

    IncMonth(StrToDateTime('2002-1-6'), 6); 结果是2002-7-6
      

  4.   

    通过IncMonth函数
    例如
    IncMonth(StrToDateTime('2003-07-17'),1)得到的是2003-08-17
    IncMonth(StrToDateTime('2003-07-17'),7)得到的是2004-02-17函数原型为:
    IncMonth functionReturns a date shifted by a specified number of months.UnitSysUtilsCategorydate/time routinesfunction IncMonth(const Date: TDateTime; NumberOfMonths: Integer = 1): TDateTime;DescriptionIncMonth returns the value of the Date parameter, incremented by NumberOfMonths months.  NumberOfMonths can be negative, to return a date N months previous.If the input day of month is greater than the last day of the resulting month, the day is set to the last day of the resulting month.  The time of day specified by the Date parameter is copied to the result.
      

  5.   

    当时我没找到incmonth这个函数,我就用decodedate()和encodedate()进行了处理,虽然麻烦了一点,但效果也不错, 就是用encodedate()先分解年、月、日,处理完后再用encodedate(),还原。有点麻烦了。