addMonths(datetime, months) Last updated: 30. May 2026

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

See also: Compare date field with todays date Get todays date SetCulture date og number format

Parameters

Name Type Description
datetime datetime

Date on which to add months to.

months number

How many months to add to specified datetime (integer only).

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 dt = new Date(); // Create new date and time object
    
    write("Before: ");
    write(format(dt, "dd. MMM yyyy")); // output time
    write("<br>");
    
    dt = docly.addMonths(dt, 3); // Add months
    write("After:");
    write(format(dt, "dd. MMM yyyy")); // output time
}#

Output

The #JS code above produces the output shown below:
Before: 05. Jun 2026<br>After:05. Sep 2026