_CompareDatesWithRange
Compares two date times to determine whether they are within a specified range of each other.
Syntax
_CompareDatesWithRange(date1,date2,datePart,rangeMin,rangeMax)
Parameters
Parameters for _CompareDatesWithRange
Parameter |
Definition |
Data type |
date1 |
First date to use. |
PFDateTime |
date2 |
Second date to use. |
PFDateTime |
datePart |
Date part used to calculate the interval between date1 and date2. |
Integer |
rangeMin |
Minimum number in the range to compare with the interval between date1 and date2. |
Integer |
rangeMax |
Maximum number in the range to compare with the interval between date1 and date2. |
Integer |
Returns
True or False (Boolean), indicating whether the first date time is within the specified range of the second date time.
Notes
- Date intervals are calculated in the following way:
- Years are measured in 365- or 366-day increments, depending on the number of calendar days in the year.
Note: If the time period includes a February month with 29 days, then 366 days equal 1 year. Otherwise, 365 days equal 1 year.
- Fewer than 365 (or, as mentioned above, 366 days)—0 years.
- 365 (or 366) to 729 (or 730) days—1 year.
- 729 (or 730) to 1094 (or 1095) days—2 years.
- Months are measured in 28-, 29-, 30-, or 31-day increments, depending on the number of days in the month.
For example, if a start date is in a month with 31 days, then 31 days from the start date is one month. If the date range goes from February until September, then each month's number of days is used for the calculation. For example, 28 (or 29, if February has 29 days) days from the start date in February is one month; 31 days from the date in March is another month; 30 days from the date in April is another month; and so on.
For increments that are fewer than 28, 29, 30, or 31 days, depending on the month, the range is 0 months.
- Days are measured in 24-hour increments. For example:
- Fewer than 24 hours—0 days.
- 24 to 47 hours—1 day.
- 48 to 71 hours—2 days.
- Years are measured in 365- or 366-day increments, depending on the number of calendar days in the year.
- The method compares the interval between the specified datePart in each date time and determines whether the interval is within the range indicated by the rangeMin and rangeMax parameters. This method is useful when determining whether the age of a subject is within a specific age range. The minimum and maximum ranges are inclusive.
- Both dates are normalized before comparison. For more information, see About date time processing.
- Valid dateParts are taken from the DateTimeParts enumerator, which returns an integer constant. (An enumerator is a variable type that represents a restricted list of values.) To reference a date part, type DateTimeParts.datePart, where datePart is one of the following:
- Years
- Months
- Days
- Hours
- Minutes
- Seconds
Example
This example checks whether a reported adverse event lasts for more than six months. The rule is defined at the form level and checks the StartDate and EndDate items in that form. This rule creates a query when an adverse event lasts more than six months.
evaluate on Form Submission
value = _CompareDatesWithRange(this.StartDate.Value, this.EndDate.Value, DateTimeParts.Months, 0, 6)
when value is false
issue query on this.EndDate: Adverse Event lasted more than six months.