Unit 'DateUtils' Package
[Overview][Constants][Classes][Procedures and functions][Index] [#rtl]

WithinPastWeeks

Check whether two TDateTimes are only a number of weeks apart.

Declaration

Source position: dateutil.inc line 267

function WithinPastWeeks(

  const ANow: TDateTime;

  const AThen: TDateTime;

  const AWeeks: Integer

):Boolean;

Arguments

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.

Remark: 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

  

Check whether two TDateTimes are only a number of years apart.

WithinPastMonths

  

Check whether two TDateTimes are only a number of months apart.

WithinPastDays

  

Check whether two TDateTimes are only a number of days apart.

WithinPastHours

  

Check whether two TDateTimes are only a number of hours apart.

WithinPastMinutes

  

Check whether two TDateTimes are only a number of minutes apart.

WithinPastSeconds

  

Check whether two TDateTimes are only a number of seconds apart.

WithinPastMilliSeconds

  

Check whether two TDateTimes are only a number of milliseconds apart.

Example

Program Example49;

{ This program demonstrates the WithinPastWeeks function }

Uses SysUtils,DateUtils;

Procedure Test(ANow,ThenDateTime; AWeeks : Integer);

begin
 Write(DateToStr(Thenand ',DateToStr(ANow));
 Write(' are within ',AWeeks,' weeks: ');
 Writeln(WithinPastWeeks(ANow,Theneks));
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.

Documentation generated on: Dec 24 2024