# \[DONE\] Add a number of months to a date

**URL:** <https://community.fibery.io/t/done-add-a-number-of-months-to-a-date/4695>\
**Category:** Misc\
**Created:** [June 30, 2023, 7:52am UTC](https://community.fibery.io/t/done-add-a-number-of-months-to-a-date/4695 "2023-06-30T07:52:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jurgenappelo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/jurgenappelo/32/11935_2.png) [@jurgenappelo](https://community.fibery.io/u/jurgenappelo)\
**Post date:** [June 30, 2023, 7:52am UTC](https://community.fibery.io/t/done-add-a-number-of-months-to-a-date/4695/1 "2023-06-30T07:52:43Z")

</div>

I need to add a number of months (in Paid Terms field) to a date (in License From field).  
This is what I was able to do figure out so far:

Date(If(Month([License From]) + [Paid Terms] \> 12,Year([License From]) + 1,Year([License From])),If(Month([License From]) + [Paid Terms] \> 12,Month([License From]) + [Paid Terms] - 12,Month([License From])),Day([License From]))

Sadly, it doesn’t work. The calculated field shows exactly the same date as in License From. Nothing is being added. :-/

I’ve already spent half an hour of my life on it. Why is this so hard? Jesus.  
In Excel, I can do this in a few seconds. :-/

---

<div class="post-metadata">

**Author:** ![jurgenappelo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/jurgenappelo/32/11935_2.png) [@jurgenappelo](https://community.fibery.io/u/jurgenappelo)\
**Post date:** [June 30, 2023, 8:09am UTC](https://community.fibery.io/t/done-add-a-number-of-months-to-a-date/4695/2 "2023-06-30T08:09:00Z")

</div>

OK, I fixed a small error but the formula still doesn’t work.  
The field is not being updated with new calculated data. _sigh_

Date(  
If(  
Month([License From]) + [Paid Terms] \> 12,  
Year([License From]) + 1,  
Year([License From])  
),  
If(  
Month([License From]) + [Paid Terms] \> 12,  
Month([License From]) + [Paid Terms] - 12,  
Month([License From]) + [Paid Terms]  
),  
Day([License From])  
)

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [June 30, 2023, 8:33am UTC](https://community.fibery.io/t/done-add-a-number-of-months-to-a-date/4695/3 "2023-06-30T08:33:28Z")

</div>

It is likely that at least one entity has a day of the month that does not exist in the month which is ‘Paid terms’ in the future.  
For example, adding 1 month to January 31st will take you to February 31st, which obviously doesn’t exist.  
If this happens, the formula calculation will likely fail everywhere.

---

<div class="post-metadata">

**Author:** ![jurgenappelo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/jurgenappelo/32/11935_2.png) [@jurgenappelo](https://community.fibery.io/u/jurgenappelo)\
**Post date:** [June 30, 2023, 8:37am UTC](https://community.fibery.io/t/done-add-a-number-of-months-to-a-date/4695/4 "2023-06-30T08:37:13Z")

</div>

Thanks.  
Then the question becomes, how do I add X months to an existing date?  
I’ve been working on this for an hour already. 😞

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [June 30, 2023, 11:39am UTC](https://community.fibery.io/t/done-add-a-number-of-months-to-a-date/4695/5 "2023-06-30T11:39:33Z")

</div>

Something like this should work

```auto
Date(
  Year(CurrentDate) +
    RoundDown((Month(CurrentDate) + IntervalPeriod - 1) / 12, 0),
  Month(CurrentDate) +
    IntervalPeriod -
    12 * RoundDown((Month(CurrentDate) + IntervalPeriod - 1) / 12, 0),
  Least(
    Day(
      Date(
        Year(CurrentDate) +
          RoundDown((Month(CurrentDate) + IntervalPeriod - 1) / 12, 0),
        Month(CurrentDate) +
          IntervalPeriod +
          1 -
          12 * RoundDown((Month(CurrentDate) + IntervalPeriod) / 12, 0),
        1
      ) - Days(1)
    ),
    Day(CurrentDate)
  )
)

```

You’d use Paid Terms instead of IntervalPeriod

---

<div class="post-metadata">

**Author:** ![jurgenappelo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/jurgenappelo/32/11935_2.png) [@jurgenappelo](https://community.fibery.io/u/jurgenappelo)\
**Post date:** [June 30, 2023, 11:52am UTC](https://community.fibery.io/t/done-add-a-number-of-months-to-a-date/4695/6 "2023-06-30T11:52:16Z")

</div>

Holy crap! What a formula. I would not have been able to do that if I gave myself a whole weekend.  
And it works. Thank you!! 🙏🏻

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [July 1, 2023, 8:40am UTC](https://community.fibery.io/t/done-add-a-number-of-months-to-a-date/4695/7 "2023-07-01T08:40:30Z")

</div>

It’s actually not too dissimilar to what you were attempting, but it is more generic.  
For example, your code for calculating the year

> [@jurgenappelo](#):
>
> If(  
> Month([License From]) + [Paid Terms] \> 12,  
> Year([License From]) + 1,  
> Year([License From])  
> )

will be incorrect if the Paid Terms number is greater than 12 (which may not happen in your specific case, I realise).

By using this

`Year(CurrentDate) + RoundDown((Month(CurrentDate) + IntervalPeriod - 1) / 12, 0)`

it’s possible to have the year correct for any integer value.

Similarly, this code

`Month(CurrentDate) + IntervalPeriod - 12 * RoundDown((Month(CurrentDate) + IntervalPeriod - 1) / 12, 0)`

ensures that the month number is never greater than 12.

Finally, the last bit of code prevents the day of the month from exceeding the highest possible value for the relevant month, by comparing the day number with the last day of the month. The last day of the month is determined by calculating the first day of the subsequent month and subtracting 1 day:

```auto
Least(
Day(Date(<calculated year>,<calculated month + 1>, 1) - Days(1)),
Day(CurrentDate)
)

```

---

<div class="post-metadata">

**Author:** ![mdubakov](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/mdubakov/32/10_2.png) [@mdubakov](https://community.fibery.io/u/mdubakov)\
**Post date:** [January 9, 2025, 3:31pm UTC](https://community.fibery.io/t/done-add-a-number-of-months-to-a-date/4695/8 "2025-01-09T15:31:40Z")

</div>

`Months(x)` formula was released today

> [@January 9, 2025 / partying\_face Set any relative value in Date Filter, Batch change fields for selected entities, Improved readability in rich text fields, some new formulas](https://community.fibery.io/t/january-9-2025-set-any-relative-value-in-date-filter-batch-change-fields-for-selected-entities-improved-readability-in-rich-text-fields-some-new-formulas/8082#p-30013-monthsnumber-add-month-to-a-date-5):
>
> First release in 2025 brings you some good stuff! partying_face Set any relative value in Date Filter We’ve significantly expanded our Date Filter capabilities to support more flexible time-based filtering. When filtering by Date Field, you can now choose from convenient preset options like “today,” “yesterday,” and “one week from now,” or use the “custom date” option to select either specific dates or relative timeframes. The “is within” operator has also received a major upgrade. You now h…

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [January 9, 2025, 3:53pm UTC](https://community.fibery.io/t/done-add-a-number-of-months-to-a-date/4695/9 "2025-01-09T15:53:49Z")

</div>


