[Overview][Constants][Procedures and functions] | Reference for unit 'dateutils' (#rtl) |
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 |
True if ANow and Athen are only AMonths apart, false otherwise
WithinPastMonths compares the timestamps ANow and AThen and returns True if the difference between them is at most AMonths months apart, or False if they are further apart.
Remark: | Since this function uses the MonthsBetween function 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.
No notes exist for this page yet.