OCLOperators AddMonths
.AddMonths returns a new DateTime moved forward by a number of calendar months. Use a negative number to move backward and get an earlier date.
Syntax
aDateTime.AddMonths(numberOfMonths)
Returns
DateTime
Examples
Forward 3 months:
DateTime.Parse('2026-11-23 14:30:00').AddMonths(3)
Result: 2/23/2027 2:30:00 PM. The year rolls over.
Back 3 months (negative value):
DateTime.Parse('2026-11-23 14:30:00').AddMonths(-3)
Result: 8/23/2026 2:30:00 PM
End of month behaviour
If the target month has fewer days, the result is moved to the last day of that month:
DateTime.Parse('2026-01-31').AddMonths(1).ToString('yyyy-MM-dd')
Result: 2026-02-28
Model example
Employees who reached their probation end (6 months after hire):
Employee.allInstances->select(e | e.HireDate.AddMonths(6) <= DateTime.Today)
Notes
- The argument must be a whole number.
- Months have different lengths, so
.AddMonths(1)is not the same as.AddDays(30).
