Docly Developers
Function Updated 19 Oct 2026

addMonths(datetime, months)

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

Parameters

datetimedatetimerequired

Date on which to add months to.

monthsnumberrequired

How many months to add (whole number, may be negative). A decimal number gives null instead of a date.

Returns

A new date; the input date is not changed. Returns null if the input is not a valid date or the number is not a whole number.

Example

Mixed HTML (or any text file) with inline JavaScript between hash signs.
#{
    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
}#