Months between dates

Hi,

I have some tasks each having Start Date and an End Date . I want to get the amount of months including the Start Date and End Date months for example if a task would have a Start Date: January 20th 2022 and the EndDate: February 26th 2022. The Amount if months would be 2 or if the StartDate: March 12th 2022 and EndDate: August 9th 2022 the amount would be 6. How can I achieve this with an expression? 

Thanks in advance!

Solved Solved
0 4 195
1 ACCEPTED SOLUTION

1 + MONTH([endDate]) - MONTH([startDate])
+ 12 * (YEAR([endDate]) - YEAR([startDate]))

That should calculate all cases ๐Ÿ™‚

Yet as Suvrutt said, dates of Jan 31st 2022 and Feb 1st 2022, will return 2 months, is that what you want?

View solution in original post

4 REPLIES 4

You also have to consider year as the scope could be November - February.

@Ratatosk  is correct. You may want to mention, if the calendar years can be different and if there can the difference be more than one year?

Are following possibilities there?

StartDate: March 12th 2021 and EndDate: August 20th 2022

StartDate: March 12th 2018 and EndDate: December 19th 2022

StartDate: January 12th 2022 and EndDate: February 8th 2023

Also will StartDate: March 31st 2022 and End Date: 1st May 2022 be 3 months even though the elapsed days are just 31?

Depending on the year overlaps, your edge cases etc., the expression will change significantly.

 

1 + MONTH([endDate]) - MONTH([startDate])
+ 12 * (YEAR([endDate]) - YEAR([startDate]))

That should calculate all cases ๐Ÿ™‚

Yet as Suvrutt said, dates of Jan 31st 2022 and Feb 1st 2022, will return 2 months, is that what you want?

Hi, thank you for your answer!

I tried it out and it seems to work exactly how I want, it should indeed return 2 months since I need the number of months the project spans over instead of the days. The actual days are irrelevant in my case.

Thanks again for your answer!

Top Labels in this Space