Forums

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

Having issues finding difference between 2 dates

Kevin Wujcik
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 16, 2025

Hello.

In a scheduled automation, I am trying to calculate the difference between the current day and the Target Start day.  The automation runs successfully, but the variable that I am trying to put the value into is blank.  Any suggestions?  Here is the Smart Value I am using:

{{issue.Target Start.diff(now)}}

I have confirmed that I can move both values (issue.Target Start and now) into variables successfully.  I've also tried to use those variables as a work around but no luck there.

Any ideas are greatly appreciated!

3 answers

1 accepted

5 votes
Answer accepted
Trudy Claspill
Community Champion
July 16, 2025

Hello @Kevin Wujcik 

Welcome to the Atlassian community.

Can you please provide screen images showing the entire automation rule?

What is the field type for Target Start? Is it a Date field, Date/Time field, or something else?

One thing that I notice is that you did not specify the unit for output. Do you want weeks, days, hours, ...?

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

{{[date1].diff([date2]).[unit]}}

Try adding the unit to the smart value and see if that improves your results.

Kevin Wujcik
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 16, 2025

I'm looking for the field definition for Target Start, but it is the default field type used by Advanced Roadmaps.

Good catch on the unit. I updated accordingly and unfortunately still no luck there ({{issue.Target Start.diff(now).days}}).  Same results.

Does this give you what you were looking for?

Screenshot 2025-07-16 163738.png

Like John Funk likes this
Trudy Claspill
Community Champion
July 16, 2025

I found the answer here:

https://confluence.atlassian.com/automationkb/how-to-use-smart-values-in-automation-rules-to-compare-the-the-target-start-and-target-end-date-fields-1115156802.html

Though that article says it is applicable to Data Center the same solution works for Cloud.

Try this:

{{issue.Target Start.toDate("yyyy-MM-dd").diff(now)}}

I tried that in my own system and it worked.

Also make sure that "Target Start" is the proper name for the field. In my system it is "Target start" with a lower case "s". Automation rule references to field names can be case sensitive.

Like # people like this
Kevin Wujcik
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 16, 2025

Looks like that was it!  Thank you so much for your help!

Like # people like this
Trudy Claspill
Community Champion
July 16, 2025

You're welcome!

Like John Funk likes this
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.
July 16, 2025

Hi @Kevin Wujcik -- Welcome to the Atlassian Community!

The built-in Target Start and Target End fields' values provided to rules are text representing a date value.  They cannot be used with the diff() function until they are converted with toDate:

https://support.atlassian.com/cloud-automation/docs/examples-of-using-smart-values-with-dates/#Converting-text-to-dates

For example:

{{issue.Target start.toDate.diff(now).days}}

(Although you may want to reverse the values if the target is in the future.)

 

And if you want to set the value of the target fields, I believe that must be done using a JSON expression.

 

Kind regards,
Bill

0 votes
Vitalii Rybka
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 16, 2025

Hi Kevin!

The issue is likely with the field name format and .diff() method syntax. Try these solutions:

1. Field name format: Custom fields with spaces need quotes or underscores:

{{issue."Target Start".diff(now)}}

or

{{issue.customfield_XXXXX.diff(now)}}

2. Check the diff() method: The .diff() method returns milliseconds by default. Try:

{{issue."Target Start".diff(now).dividedBy(86400000)}}

(This converts to days)

3. Alternative approach:

{{now.diff(issue."Target Start").dividedBy(86400000)}}

(This gives positive numbers for past dates)

4. For debugging: Add this to see what's actually in your field:

Target Start: {{issue."Target Start"}}
Now: {{now}}
Diff: {{issue."Target Start".diff(now)}}

5. Date format check: Make sure your "Target Start" field is actually a date/datetime field type, not text.

Try these and let me know what you see!

Best, Vitaliy

DM me if you need more help!

Kevin Wujcik
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 16, 2025

Thank you for the suggestions, Vitalii.  Trudy's answer above worked.

Suggest an answer

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

Atlassian Community Events