[Overview][Constants][Procedures and functions] Reference for unit 'dateutils' (#rtl)

WithinPastMonths

Check whether two datetimes are only a number of months apart

Declaration

Source position: dateutil.inc line 242

function WithinPastMonths(

  const ANow: TDateTime;

  const AThen: TDateTime;

  const AMonths: Integer

):Boolean;

Arguments

ANow

  

First moment in time

AThen

  

Second moment in time

AMonths

  

Number of months to check

Function result

Trueif ANowand Athenare only AMonthsapart, falseotherwise

Description

WithinPastMonthscompares the timestamps ANowand AThenand returns Trueif the difference between them is at most AMonthsmonths apart, or Falseif they are further apart.

Remark: Since this function uses the MonthsBetweenfunction to calculate the difference in Months, this means that fractional months do not count, and the fractional part is simply dropped, so for two dates actually 2 and a half months apart, the result will also be True

See also

WithinPastYears

  

Check whether two datetimes are only a number of years apart

WithinPastWeeks

  

Check whether two datetimes are only a number of weeks apart

WithinPastDays

  

Check whether two datetimes are only a number of days apart

WithinPastHours

  

Check whether two datetimes are only a number of hours apart

WithinPastMinutes

  

Check whether two datetimes are only a number of minutes apart

WithinPastSeconds

  

Check whether two datetimes are only a number of seconds apart

WithinPastMilliSeconds

  

Check whether two datetimes are only a number of milliseconds apart

Example

Program Example48;

{ This program demonstrates the WithinPastMonths function }

Uses SysUtils,DateUtils;

Procedure Test(ANow,AThen : TDateTime; AMonths : Integer);

begin
 Write(DateToStr(AThen),' and ',DateToStr(ANow));
 Write(' are within ',AMonths,' months: ');
 Writeln(WithinPastMonths(ANow,AThen,AMonths));
end;

Var
  D1,D2 : TDateTime;

Begin
  D1:=Today;
  D2:=Today-364;
  Test(D1,D2,12);
  D2:=Today-365;
  Test(D1,D2,12);
  D2:=Today-366;
  Test(D1,D2,12);
  D2:=Today-390;
  Test(D1,D2,12);
  D2:=Today-368;
  Test(D1,D2,11);
  D2:=Today-1000;
  Test(D1,D2,31);
  Test(D1,D2,32);
  Test(D1,D2,33);
End.