Date.AddMonths
Moves a date, datetime or datetimezone by calendar months, keeping the day of the month where it can.
Group: Dates and times. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Date.AddMonths(dateTime as any, numberOfMonths as number) as any
| Parameter | Type | Description |
|---|---|---|
dateTime | any | The date, datetime or datetimezone to move; null gives null. |
numberOfMonths | number | How many months to move: negative goes back in time. |
Returns
any. The same kind of value as given, moved by that many months.
Remarks
- A date gives a date, a datetime a datetime, a datetimezone a datetimezone with its offset unchanged; the time of day is kept.
- When the target month is shorter, the day becomes that month's last day: 31 January plus one month is the end of February. Moving back again does not restore the 31st.
Examples
The same day next month
Date.AddMonths(#date(2024, 3, 15), 1)
#date(2024, 4, 15)
From the end of January
Date.AddMonths(#date(2024, 1, 31), 1)
#date(2024, 2, 29)
February 2024 has no 31st, so the answer is its last day, the 29th.
The same day a year earlier, in months
Date.AddMonths(#date(2024, 3, 15), -12)
#date(2023, 3, 15)
Related functions
Date.AddQuarters, Date.AddYears, Date.EndOfMonth, Date.StartOfMonth.