Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Automation - Calculating total months between two dates

Madar_ Andrew
Contributor
May 29, 2024

Is this the proper syntax to calculate the number of months between two dates?

 

{{issue.Budget Coverage Period (Start date).diff(issue.Budget Coverage Period (End date)).months.abs}}

 

Thank you,

 

1 answer

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2024

Hi @Madar_ Andrew 

For a question like this, please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected.  Those will provide context for the community to offer ideas.  Thanks!

Until we see those...

The syntax you show appears correct.  To confirm, are those both date (or date / time) fields, and are those the correct smart values for the fields?

Smart values are name, spacing, and case-sensitive...and they often do not exactly match the display names of the fields on the issue pages.  When an incorrect smart value is used, it is replaced with null and often fails with no errors.

To confirm you have the correct smart values (or custom field ids) for your fields, please use this how-to article:

https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/

 

Kind regards,
Bill

Trudy Claspill
Community Champion
May 29, 2024

Adding to this...

@Madar_ Andrew Have you tried to use what you've shown? Did you get an error or an unexpected result?

I wonder if the parentheses within the field names might be causing problems?

Perhaps if those were replaced with the custom field ID instead, then the rule would work.

Madar_ Andrew
Contributor
May 29, 2024

Budget Coverage Period (Start date)=2024-06-01
Budget Coverage Period (End date)=2024-12-31

{{issue.Budget Coverage Period (Start date).diff(issue.Budget Coverage Period (End date)).months.abs}}

The value returned is 6.

It should be 7.  I have to perform a plus 1.

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2024

The difference appears to be a mathematical difference (i.e., 12 - 6) and not an inclusive one, counting the end points.

Madar_ Andrew
Contributor
May 29, 2024

Any idea how to obtain the number of months which should be 7?

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2024

Will your dates always be the start / end of months?  If so, add one day to the end date before performing the math.

{{issue.Budget Coverage Period (Start date).diff(issue.Budget Coverage Period (End date).plusDays(1)).months.abs}}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events