AddToDate function
Syntax
AddToDate(date, num_years, num_months, num_days)
Description
Use the AddToDate function to add the specified number of years, months, and days to the date provided.
Suppose, for example, that you want to find a date six years from now. You could not just multiply 6 times 365 and add the result to today’s date, because of leap years. And, depending on the current year, there may be one or two leap years in the next six years. AddToDate takes care of this for you.
You can subtract from dates by passing the function negative numbers.
Parameters
| Parameter | Description |
|---|---|
|
date |
The input date to be adjusted. |
|
num_years |
The number of years by which to adjust the specified date. num_years can be a negative number. |
|
num_months |
The number of months by which to adjust the specified date. This parameter can be a negative number. |
|
num_days |
The number of days by which to adjust the specified date. This parameter can be a negative number. |
Returns
Returns a Date value equal to the original date plus the number of years, months, and days passed to the function.
Example
The following example finds the date one year, three months, and 16 days after a field called BEGIN_DT:
AddToDate(BEGIN_DT, 1, 3, 16);
This example finds the date two months ago prior to BEGIN_DT:
AddToDate(BEGIN_DT, 0, -2, 0);
Considerations Using AddToDate
When you are adding one month to the date provided, and the date provided is the last day of a month, and the next month is shorter, the returned result is the last day of the next month.
For example, in the following, &NewDate is 29/02/2004:
&NewDate = AddToDate("31/01/2004", 0, 1, 0);
When you are adding one month to the date provided, and the date provided is the last day of a month, and the next month is longer, the returned result is not the last day of the next month.
For example, in the following, &NewDate is 29/03/2004.
&NewDate = AddToDate("29/02/2004", 0, 1, 0)