_CalculateDateTime

Calculates a new date and time by adding an interval to or subtracting an interval from another date and time. The interval is based on a date part, for example, a number of days.

Syntax

_CalculateDateTime(date,interval,datePart)

Parameters
Parameter Definition Data type

date

Original date and time.

PFDateTime

interval

Time interval to add to or subtract from the original date time.

Integer

datePart

Date part to which the value specified in the interval parameter is added.

Integer

Returns

New date time (PFDateTime).

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.
  • The new date time is based on the sum of the original date time and the interval.
  • Before the interval is added, the date is normalized. For more information, see 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 sets a date for follow-up that is four weeks after the initial date entered. Both items are on the same form, so the rule is created at the form level. There is no enumeration for weeks in DateTimeParts, so the rule uses twenty-eight days instead of four weeks.

Note:

Oracle recommends that you include rule logic to clear the calculated value if a referenced item value is cleared. For example, if a rule calculates BMI based on the values entered in the Height and Weight items, the rule should clear the BMI value if the data in the Height item is deleted. For an example of the appropriate rule logic, see Sample data-entry rules that use methods.
evaluate on Form Submission
    value = _CalculateDateTime(this.InitialExamDate.Value, 28, DateTimeParts.Days)
always
    set this.FollowupExamDate.Value = value