[Overview][Constants][Procedures and functions] |
Check whether two datetimes are only a number of months apart
Source position: dateutil.inc line 242
function WithinPastMonths( |
const ANow: TDateTime; |
const AThen: TDateTime; |
const AMonths: Integer |
):Boolean; |
ANow |
|
First moment in time |
AThen |
|
Second moment in time |
AMonths |
|
Number of months to check |
Trueif ANowand Athenare only AMonthsapart, falseotherwise
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 |
|
Check whether two datetimes are only a number of years apart |
|
|
Check whether two datetimes are only a number of weeks apart |
|
|
Check whether two datetimes are only a number of days apart |
|
|
Check whether two datetimes are only a number of hours apart |
|
|
Check whether two datetimes are only a number of minutes apart |
|
|
Check whether two datetimes are only a number of seconds apart |
|
|
Check whether two datetimes are only a number of milliseconds apart |
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.