AddYears(datetime, years) Last updated: 21. Dec 2022

Adding a number of days (positive or negative value) to a specified date.

Parameters

Name Type Description
datetime Datetime object Date on which to add days to.
years number (int only) How many years to add to specified datetime.

Returns

A modified date, does not modify input date.

Example

Code example (#JS)

#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.
#{
    var before = new Date(); // Create new date and time object
    var after = docly.addYears(before, 3); // Add  years
}#
<b>Before:</b> #format(before, "dd. MMM yyyy")#<br>
<b>After:</b> #format(after, "dd. MMM yyyy")#

Output

The #JS code above produces the output shown below:
<b>Before:</b> 03. Dec 2024<br>
<b>After:</b> 03. Dec 2027