Arithmetic date expressions


Addition and subtraction of date values is defined as described below. It does not matter whether the date to be operated on is a Gregorian or Julian date. Because all dates are normalized, both formats are identical internally.

Related topic

Addition

A specified number of years, months, or days can be added to a date. Two dates cannot be added together. The quantity to be added is designated by a system data operator indicating the measurement (&YEARS, &MONTHS, &DAYS) preceding the value to be added. If the unit of measurement is not specified, it is assumed to be &DAYS.

If the value being added to a date is negative, it is equivalent to subtracting its absolute value.

Example
 NEXTDATE %YYYYMMDD + &DAYS SEG.NUMDAYS
START%YYDDD + &YEARS 30
&DATE + &DAYS(SICK + VACATION)

Subtraction

Two dates can be subtracted, the difference being the signed number of days between the two dates.

The result will be negative if the first date precedes the second date. A specified number of years, months, or days can be subtracted from a date. The quantity to be subtracted is designated by a system data operator indicating the measurement ( &YEARS, &MONTHS, &DAYS) preceding the value to be subtracted.

If the value being subtracted from a date is negative, it is equivalent to adding its absolute value.

Example
NEXTDATE%YYYYMMDD - &DAYS SEG.NUMDAYS
END%YYDDD - &YEARS 30
&DATE - &DAYS(SICK + VACATION)
ENDDATE - BEGDATE
Example

The result of subtracting two dates is recognized as being a number of days and need not be preceded by the &DAYS system data operator.

 &DATE + (ENDDATE - BEGDATE)

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*