Forums

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

How to calculate the difference between two dates and output the number of days

Charles Brooks
Contributor
March 20, 2025

Trying to calculate the difference between two different dates and output the number of days in another field within Jira.  Then how to set a value to 1 when the number of days equal Zero.

2 answers

1 accepted

3 votes
Answer accepted
Trudy Claspill
Community Champion
March 20, 2025

Hello @Charles Brooks 

Welcome to the Atlassian community.

Without a third party app you would need to use an Automation Rule to accomplish that. Are you familiar with Automation Rules?

https://support.atlassian.com/cloud-automation/docs/jira-cloud-automation/

You may have to work with a Project Admin or a Jira Administrator to get the rule constructed if you don't have sufficient permissions.

If you are unfamiliar with the feature you can find free, on-demand training from Atlassian at 

https://university.atlassian.com

With an automation rule you could use the diff function to get the differences between two date fields.

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/#Date-difference---

Charles Brooks
Contributor
March 20, 2025

I am familiar using the Automation portion of Jira

Charles Brooks
Contributor
March 20, 2025

The issue, I'm having is that I need a specific Date field within my project, to do the calculation.  For example when I use the Smart Value, and type for the Field Due Date, I get multiple choices and don't know which one to use.

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.
March 20, 2025

Hi @Charles Brooks -- Welcome to the Atlassian Community!

If there are multiple fields with the same name causing confusion (which is a different problem), you can identify the needed one using this how-to article:

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

The essential steps are to identify and example issue with your field, use a browser tab to call the REST API, search on the page for your field, and the likely use the custom field ID to select the correct one.

Kind regards,
Bill

Like Trudy Claspill likes this
Charles Brooks
Contributor
March 20, 2025

Thanks for your reply, the date field I'm trying to use is a System Field called "Due date", maybe I'm better off creating a custom date field.

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.
March 20, 2025

Due Date is one of the pesky built-in fields that has multiple smart values.  Please try this one in your expression:

{{issue.duedate}}

 

Like Trudy Claspill likes this
Trudy Claspill
Community Champion
March 20, 2025

@Charles Brooks 

Can you provide a screen image of where you are seeing the multiple choices?

Charles Brooks
Contributor
March 24, 2025

image.png

I have 7 choices for the Field Due date, since this field is a system field in Jira.  

Trudy Claspill
Community Champion
March 25, 2025

Thank you for that additional information.

Can you provide a more complete screen image? It seems that you might be using some of the AI/helper functionality to help you construct the rule. I am not using any of that functionality, so I don't get the same screen.

Or you can just try the smart value suggested by @Bill Sheboy . He did provide the correct value if the field you are trying to access is the system provided Due Date field.

Charles Brooks
Contributor
March 25, 2025

I have tried using the system field Due Date, inside my formula but I still can't get it to work.  I must be doing somethingScreenshot 2025-03-25 150111.png incorrectly here.

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.
March 25, 2025

Charles, what do you observe happening that is not working as expected?

And, would you please post:

  • an image of the Edit Issue Fields action and
  • an image of the audit log details showing the rule execution, expanding all the details at the right side

Thanks!

Like Trudy Claspill likes this
Charles Brooks
Contributor
March 26, 2025

Screenshot 2025-03-26 070946.pngScreenshot 2025-03-26 071034.pngScreenshot 2025-03-26 071101.pngScreenshot 2025-03-26 071511.pngScreenshot 2025-03-26 071546.pngScreenshot 2025-03-25 150111.pngScreenshot 2025-03-26 070920.png

Trudy Claspill
Community Champion
March 26, 2025

Hello @Charles Brooks 

I see a typo in the smart value in your Edit Issue action.

You are using

{{issue.customfield_11957}.diff(issue.duedate).days}}

Notice the "}" character immediately to the right of the "7". You need to remove that character.

Like Bill Sheboy likes this
Charles Brooks
Contributor
March 26, 2025

Now it's working, but when I have a Due Date and Completion on the same day I get a value of zero.  I need the value to say 1 , not Zero, how would I do that.

Trudy Claspill
Community Champion
March 26, 2025

The diff() function is returning the correct value. If the two date fields are the same, the difference is 0.

If the dates one day off (i.e. today and tomorrow), would you want to record a value of 1 or 2?

Have you considered all your scenarios?

  1. The two fields have the same date.
  2. Completion date is before Due date.
  3. Due date is before Completion date.
  4. The dates in between Completion and Due include weekend or holiday dates?
Like # people like this
Charles Brooks
Contributor
July 11, 2025

Sometimes tasks are created today and I can complete the same day, so I need to show that it took 1 day, not 0 days.

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.
July 11, 2025

Hi @Charles Brooks 

After you have defined all possible cases for testing, as Trudy suggests, you could use a math expression and the MAX() function to ensure the value is always at least 1.

For example:

{{#=}}MAX(1, {{issue.customfield_11957.diff(issue.duedate).days}} ){{/}}

 

Kind regards,
Bill

Like Trudy Claspill likes this
Charles Brooks
Contributor
July 11, 2025

Thanks Bill for the help, I really appreciate everyone's help on this forum.

Like # people like this
0 votes
Charles Brooks
Contributor
March 26, 2025

I don't see any value in the field called Inspection Time, even though it was successful

Suggest an answer

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

Atlassian Community Events