[Overview][Constants][Procedures and functions] |
Check whether two datetimes are only a number of weeks apart
Source position: dateutil.inc line 243
function WithinPastWeeks( |
const ANow: TDateTime; |
const AThen: TDateTime; |
const AWeeks: Integer |
):Boolean; |
ANow |
|
First moment in time |
AThen |
|
Second moment in time |
AWeeks |
|
Number of weeks to check |
Trueif ANowand Athenare only AWeeksapart, falseotherwise
WithinPastWeekscompares the timestamps ANowand AThenand returns Trueif the difference between them is at most AWeeksweeks apart, or Falseif they are further apart.
Remark: | Since this function uses the WeeksBetweenfunction 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 |
|
Check whether two datetimes are only a number of years apart |
|
|
Check whether two datetimes are only a number of months 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 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.