You are here:
Configure End of Month Logic in Formula Nodes
When adding or subtracting months in DPE formula nodes, standard date calculations may not accurately land on the last day of the target month. This occurs because month lengths vary, and leap years affect February. For example, subtracting one month from April 30th (the end of the month) typically results in March 30th, which is not the last day of March. However, your business rule might require the date to be March 31st (or February 29th/28th if applicable).
Use the following examples in your formula node configuration to ensure your end-of-month calculations land on the last day of the month.
Example for 12-Month Subtraction
If your date field is February 28th 2025 (end of month) and upon subtracting 12 months, the date should land on February 29th 2024 (end of month), input the following formula into your Formula node:
IF(
(SUBSTR(TEXT({Datefield}),6,2) != SUBSTR(TEXT(ADDDAYS({Datefield},1)),6,2)),
ADDDAYS(
DATEVALUE(
CONCAT(
SUBSTR(TEXT(ADDMONTHS(ADDMONTHS({Datefield},-12),1)),0,8), "01"
), "yyyy-MM-dd"
), -1
),
ADDMONTHS({Datefield}, -12)
)Example for 12-Month Addition
If your date field is February 28th 2023 (end of month) and upon adding 12 months, the date should land on February 29th 2024 (end of month), input the following formula into your Formula node:
IF(
(SUBSTR(TEXT({Datefield}),6,2) != SUBSTR(TEXT(ADDDAYS({Datefield},1)),6,2)),
ADDDAYS(
DATEVALUE(
CONCAT(
SUBSTR(TEXT(ADDMONTHS(ADDMONTHS({Datefield},12),1)),0,8), "01"
), "yyyy-MM-dd"
), -1
),
ADDMONTHS({Datefield}, 12)
)