# Set duration for month automatically

**URL:** <https://community.fibery.io/t/set-duration-for-month-automatically/4250>\
**Category:** Get Help\
**Created:** [April 4, 2023, 6:47pm UTC](https://community.fibery.io/t/set-duration-for-month-automatically/4250 "2023-04-04T18:47:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marloes](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/marloes/32/5926_2.png) [@Marloes](https://community.fibery.io/u/Marloes)\
**Post date:** [April 4, 2023, 6:47pm UTC](https://community.fibery.io/t/set-duration-for-month-automatically/4250/1 "2023-04-04T18:47:58Z")

</div>

Hi,

I have build an automation where every 12 months a new year is being created. After a year is being created, months are created. For these months I would like to automatically set the duration.

The duration for every month is known when created, except for february.

- January is always _Jan 1 - Jan 31_ + ToText(Year(Today()) + 1)  
Is there a way to create a formula like this to set the duration?

- February is slightly different. Start date is always known → Feb 1.  
The end date is either Feb 28th or Febr 29th.

Is there a solution for this?

I hope it is clear what I am trying to achieve.

Thanks!

---

<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:** [April 4, 2023, 8:37pm UTC](https://community.fibery.io/t/set-duration-for-month-automatically/4250/2 "2023-04-04T20:37:50Z")

</div>

The easiest way to get the last day of any given month is to get the first day of the next month, and then subtract a day.  
So to get the number of the last day of February next year, try something like this:

`Day(Date(Year(Today()) + 1,3,1) - Days(1))`

Explanation:  
`Date(Year(Today()) + 1,3,1)` will get you 1st March 2024,  
`Date(Year(Today()) + 1,3,1) - Days(1)` will get you the previous day (e.g. 29th February 2024)  
`Day(Date(Year(Today()) + 1,3,1) - Days(1))` gets you the number 29

---

<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:** [April 4, 2023, 8:39pm UTC](https://community.fibery.io/t/set-duration-for-month-automatically/4250/3 "2023-04-04T20:39:07Z")

</div>

You may actually find that your formulas for other months could be simplified as well, using the same principle, so you wouldn’t need to ‘hard-code’ any specific number of days in the month.

---

<div class="post-metadata">

**Author:** ![Marloes](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/marloes/32/5926_2.png) [@Marloes](https://community.fibery.io/u/Marloes)\
**Post date:** [April 6, 2023, 7:07am UTC](https://community.fibery.io/t/set-duration-for-month-automatically/4250/4 "2023-04-06T07:07:23Z")

</div>

Thanks @Chr1sG ,

This is better than I was hoping for! One last question in addition to the above.

With those dates you have either a start datum or an end date of a month. Is there a way to combine those to into one single date field with start and end date?

Thanks!

---

<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:** [April 6, 2023, 8:47am UTC](https://community.fibery.io/t/set-duration-for-month-automatically/4250/5 "2023-04-06T08:47:14Z")

</div>

You can construct a date range using the formula `DateRange(Start, End)`  
where Start and End are Date values (from fields, or from formulas themselves)

---

<div class="post-metadata">

**Author:** ![Marloes](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/marloes/32/5926_2.png) [@Marloes](https://community.fibery.io/u/Marloes)\
**Post date:** [April 6, 2023, 12:55pm UTC](https://community.fibery.io/t/set-duration-for-month-automatically/4250/6 "2023-04-06T12:55:57Z")

</div>

Yes, this does the work! I was trying to set a date field instead of using a formula field. Thanks!
