WithinPastWeeks function
Check whether two TDateTimes are only a number of weeks apart.
Declaration
function WithinPastWeeks(const ANow: TDateTime; const AThen: TDateTime;
const AWeeks: Integer): BooleanArguments
ANow | First moment in time. |
AThen | Second moment in time. |
AWeeks | Number of weeks to check. |
Function result
True if
ANow and
Athen are only
AWeeks apart,
false otherwise.Description
WithinPastWeeks compares the timestamps
ANow and
AThen
and returns
True if the difference between them is at most
AWeeks weeks apart, or
False if they are further
apart.
Since this function uses the WeeksBetween function to calculate
the difference in Weeks, this means that fractional Weeks do not count, and
the fractional part is simply dropped, so for two dates actually 2 and a half
weeks apart, the result will also be
True
See also
- WithinPastYears
- WithinPastMonths
- WithinPastDays
- WithinPastHours
- WithinPastMinutes
- WithinPastSeconds
- WithinPastMilliSeconds
Example: ex49
Program Example49;
{ This program demonstrates the WithinPastWeeks function }
Uses SysUtils,DateUtils;
Procedure Test(ANow,AThen : TDateTime; AWeeks : Integer);
begin
Write(DateToStr(AThen),' and ',DateToStr(ANow));
Write(' are within ',AWeeks,' weeks: ');
Writeln(WithinPastWeeks(ANow,AThen,AWeeks));
end;
Var
D1,D2 : TDateTime;
Begin
D1:=Today;
D2:=Today-7;
Test(D1,D2,1);
D2:=Today-8;
Test(D1,D2,1);
D2:=Today-14;
Test(D1,D2,1);
D2:=Today-35;
Test(D1,D2,5);
D2:=Today-36;
Test(D1,D2,5);
D2:=Today-17;
Test(D1,D2,1);
Test(D1,D2,2);
Test(D1,D2,3);
End.An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
