_GetDateDifference
Returns the number of units between two specified dates, based on the requested date part.
Syntax
_GetDateDifference(date1,date2,units)
Parameters
Parameters for _GetDateDifference
Parameter |
Definition |
Data type |
date1 |
First date to use. date1 is subtracted from date2. |
PFDateTime |
date2 |
Second date to use. |
PFDateTime |
units |
Unit to use when computing the difference. Units are taken from DateTimeParts: Years, Months, Days, Hours, Minutes, Seconds. |
Integer |
Returns
A positive, zero, or negative interval length depending on whether the first date is earlier than, equal to, or later than the second date. Unknown date parts are normalized. Results are rounded down.
Notes
- GetDateDifference returns positive value if date1 is before date2 and returns a negative value when date 2 is before date 1.
- 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.
- 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
- Dates are normalized before the number of units is calculated. For more information, see About date time processing.
- The entire date is used in the calculation, not only the specified date part. Results are rounded down to the nearest integer. For example, if _GetDateDifference runs with the following data, it returns 0, not 1:
_GetDateDifference (new DateTime(2007,1,10,0,0,0), new DateTime (2007,2,1,0,0,0), DateTimeParts.Months)
Example
The _GetDateDifference function is used to determine how long an adverse event lasts and to store the result in an item. This rule is attached to the AE form, which contains the OnsetDate and EndDate items, as well as an AEDuration item to store the calculated value.
evaluate on Form Submission
value = _GetDateDifference(this.OnsetDate.Value, this.EndDate.Value, DateTimeParts.Days)
always
set this.AEDuration.Value = value
If OnsetDate is January 1, 2008, and EndDate is January 6, 2008, the function returns 5.