Skip to content

IncMonth

Increases the month in a TDateTime value with a given amount.

Declaration

Source position: datih.inc line 132

  function IncMonth(const DateTime: TDateTime; NumberOfMonths: Integer)
                    : TDateTime;

Description

IncMonth increases the month number in DateTime with NumberOfMonths. It wraps the result as to get a month between 1 and 12, and updates the year accordingly. NumberOfMonths can be negative, and can be larger than 12 (in absolute value).

Errors

None.

See also

Name Description
Date Return the current date.
Now Returns the current date and time.
Time Returns the current time.

Example

Program Example15;
{ This program demonstrates the IncMonth function }
Uses sysutils;
Var ThisDay : TDateTime;
Begin
  ThisDay:=Date;
  Writeln ('ThisDay : ',DateToStr(ThisDay));
  Writeln ('6 months ago :',DateToStr(IncMonth(ThisDay,-6)));
  Writeln ('6 months from now :' ,DateToStr(IncMonth(ThisDay,6)));
  Writeln ('12 months ago :',DateToStr(IncMonth(ThisDay,-12)));
  Writeln ('12 months from now :' ,DateToStr(IncMonth(ThisDay,12)));
  Writeln ('18 months ago :',DateToStr(IncMonth(ThisDay,-18)));
  Writeln ('18 months from now :' ,DateToStr(IncMonth(ThisDay,18)));
End.