[Overview][Constants][Procedures and functions][Index] |
Check whether two datetimes are only a number of years apart
Source position: dateutil.inc line 242
function WithinPastYears( |
const ANow: TDateTime; |
const AThen: TDateTime; |
const AYears: Integer |
):Boolean; |
ANow |
|
First moment in time |
AThen |
|
Second moment in time |
AYears |
|
Number of years to check |
True if ANow and Athen are only AYears apart, false otherwise
WithinPastYears compares the timestamps ANow and AThen and returns True if the difference between them is at most AYears years apart, or False if they are further apart.
Remark: | Since this function uses the YearsBetween function to calculate the difference in years, this means that fractional years do not count, and the fractional part is simply dropped, so for two dates actually 2 and a half years apart, the result will also be True |
|
Check whether two datetimes are only a number of months 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 Example47; { This program demonstrates the WithinPastYears function } Uses SysUtils,DateUtils; Procedure Test(ANow,AThen : TDateTime; AYears : Integer); begin Write(DateToStr(AThen),' and ',DateToStr(ANow)); Write(' are within ',AYears,' years: '); Writeln(WithinPastYears(ANow,AThen,AYears)); end; Var D1,D2 : TDateTime; Begin D1:=Today; D2:=Today-364; Test(D1,D2,1); D2:=Today-365; Test(D1,D2,1); D2:=Today-366; Test(D1,D2,1); D2:=Today-390; Test(D1,D2,1); D2:=Today-368; Test(D1,D2,1); D2:=Today-1000; Test(D1,D2,1); Test(D1,D2,2); Test(D1,D2,3); End.
lazarus-ccr.sourceforge.net |