Previous Topic: *DATE INCREMENT Rules and Examples

Next Topic: Understanding Contexts

*DURATION Rules and Examples

*DURATION performs the following operation:

End date - Start date = Duration

The *DURATION function result is often not as obvious and easily predictable as the *DATE INCREMENT result. For example, what is the duration expressed in *MONTHS between Start date (December 31, 1995) and End date (February 29, 1996)? The function returns two months even though three months are involved in the calculation. This is another example of the Everyday calendar’s approximation.

The remainder of this section gives examples of specific assumptions CA 2E makes to adjust results to common sense standards and to produce consistent results.

Start date

End date

Duration

Actual Days

December 31, 1995

January 31, 1996

1 (*MONTHS)

31

December 19, 1995

January 23, 1996

1 (*MONTHS)

35

December 28, 1995

January 23, 1996

0 (*MONTHS)

26

January 31, 1996

February 29, 1996

1 (*MONTHS)

29

Start date

End date

Duration

Actual Days

December 31, 1995

December 31, 1996

1 (*YEARS)

365

December 31, 1996

December 31, 1997

1 (*YEARS)

365

June 30, 1996

June 30, 1997

1 (*YEARS)

365

Start date

End date

Duration

Actual Days

November 12, 1995

March 23, 1997

1 (*YEARS)

497

November 12, 1995

March 23, 1997

16 (*MONTHS)

497

November 12, 1995

March 23, 1997

104 (*YYMM)

497

November 12, 1995

March 23, 1997

10410 (*YYMMDD)

497

Following are the steps used to produce this result.

  1. Calculate years. From within the range of dates, identify any whole years consisting of 12 consecutive whole months. For example, December 1, 1995 to November 30, 1996 = 1 year.
  2. Calculate months. From within the remaining dates, identify any whole months; in this example, December 1996 + January 1997 + February 1997 = 3 months.
  3. Calculate days. All that remains from the original date range are parts of the first and last months in the range; namely, November 12, 1995 to November 30, 1995 (18 days) and March 1, 1997 to March 23, 1997 (23 days). The total number of remainder days is 41 (18 + 23 = 41). Since 41 days is greater than the Duration month of 31, add one month to the total number of months (3 + 1 = 4 months).

    Recall that the DD portion of the *YYMMDD duration type represents the number of days not included in either the Duration year (YY) or the Duration month (MM). In other words, Remainder days (DD) – Duration month = 10 days (41 – 31 = 10).

The final result in *YYMMDD format is 10410.

Start date

End date

Duration

Actual Days

December 1, 1995

January 1, 1996

100

31

January 1, 1996

December 1, 1995

–100

–31

February 12, 1995

March 12, 1995

100

28

February 12, 1996

March 12, 1996

100

29

Application of this rule sometimes causes different, but close, Start and End dates to return the same duration.

Start date

End date

Duration

Actual Days

May 19, 1996

June 20, 1996

102

32

May 20, 1996

June 20, 1996

100 (2)

31

May 21, 1996

June 20, 1996

100

30

May 22, 1996

June 20, 1996

029

29

(1) The End month, June, has 30 days; so the Duration month
in this example is 30. DD=Actual Days–Duration month=02.
(2) The arithmetic result 101 is adjusted to 100 since the Start
  and End dates represent the same day in contiguous months.

Start date

End date

Duration

Actual Days

December 8, 1995

December 8, 1996

10000

366

February 1, 1995

February 1, 1996

10000

365

February 1, 1996

February 1, 1995

–10000

–365

Application of this rule sometimes causes different, but close, Start and End dates to return the same duration.

Start date

End date

Duration

Actual Days

February 28, 1995

February 29, 1996

10000

366

February 28, 1995

February 28, 1996

10000 (1)

365

(1) This result was adjusted since the Start and End dates represent the same day and month in contiguous years.