Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,064
Community Members
 
Community Events
185
Community Groups

URGENT! Calculate the difference between two dates.

Hello,

I want to calculate the difference between two dates.

I created two custom fields. A DateTime Picker to store the pull request time (called "Pull request opening date"). And another "Total pull request time" field of type Number to store the difference.

In my automation I'm doing the calculation as follows:

{{now.diff (Pull request opening date.value) .minutes}}

Is not working. Automation is performed with success, but does not generate any results. The result field is "empty". I figured the reason was that there was no a completed hour difference between dates, just minutes. So I switched to "minutes", but it still doesn't work.

 

Filtering the issue in Jira, the value of the data field is 03/Sep/20 2:35 PM.

Someone to help me?

3 answers

I am trying this very same thing trying to update a number field "Days" with the number of days that have passed since the issue Start Date. While the automation runs to success and says the issues were edited, the number field "Days" remains empty.

{{issue.startDate.diff(now).days.abs}}

I cannot figure out why this does not do anything. I've reviewed the documentation and am stumped

Minor correction - If there is a value in the Day field already, the automation is setting it to null. So this calculated value is returning null. I don't get it. 

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 12, 2023

Hi @beacon_grayson  - It is better if you create a new question in the Community. That way more people will see it and respond, and specific details to your situation can be discussed. Please post your full rule with the new question, especially showing the details of the field update in the Edit Issue component. 

Do this works for timestamp instead of dates?

I have a Timestamp called "WIN Timestamp"  saving  'now' when the WIP started and WIP Time to calculate the diff from WIP Timestamp and now.  I use the formula below  {{issue.WIP Timestamp.diff(now).minutes}} but as a resolve I got Dec 31 ,2001. Not sure what I'm missing. 

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.
Dec 17, 2020

Hi @Manrique Soto 

For something like this, please consider creating a new question or staying on the original thread.

The answer to your question is: yes.  The earlier examples all use date/time fields.  Here is an example I use to measure Lead Time in fractional days.

{{#=}}ROUND({{issue.Created.diff(issue.Resolved).millis}} / (1000*60*60*24), 3){{/}}

Please consider logging your WIP Timestamp field, as it may not be set to a date/time value or could be null.

 

Best regards,

Bill

Like Mariya Pustovalova likes this
0 votes
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 03, 2020

Hi @Dionei Piazza  - Try putting issue. in front of the field:

{{now.diff(issue.Pull request opening date.value).minutes}}

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.
Sep 03, 2020

Hi,

As this is already a date/time field, you may not need the .value part.  I didn't need it when I use custom fields of that type with smart value functions.

Best regards,

Bill

Hi @John Funk 

I tried, but it still doesn't work.

Empty field.

Hey @Bill Sheboy 

I follow de Atlassian Jira documentation of smart values.

If I understood what you said, would the automation script be like this:

{{now.diff(issue.Pull request opening date).minutes}}  ??

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 03, 2020

Yes - try that.

Hi @John Funk and @Bill Sheboy 

I did the execution with {{now.diff(issue.Pull request opening date).minutes}}  and the result was negative. :(

Start date: 04 / Sep / 20 9:46 AM
End date: 04 / Sep / 20 9:50 AM
Result: -4

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 04, 2020

Maybe you need to switch the order of the fields. 

Thanks @John Funk 

But, If I need to have the difference between "Now" and the first date that represents the "Opening of the Pull request", I think it is already in the right order.

{{now.diff(issue.Pull request opening date).minutes}}

 

What I tried now was to use "abs" to guarantee a positive number. let me see the result

{{now.diff (issue.Pull request opening date).abs.minutes}}

Interesting,

Now, looking at the documentation https://support.atlassian.com/jira-software-cloud/docs/smart-values-date-and-time-functions/

I found this:

Example
For an issue was created 4 weeks ago:
{{now.diff (issue.created) .weeks}}
// returns
-4

This issue was created {{now.diff (issue.created) .weeks.abs}} weeks ago.
// returns
This issue was created 4 weeks ago.

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.
Sep 04, 2020

Hi,

For the diff function, the earlier value comes first.  Trying what John suggests, you would use: {{issue.Pull request opening date.diff(now).minutes}}

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 17, 2020

Hi @Dionei Piazza - Did you ever get this solved?

Wondering how you folks were accounting for things like working hours and weekends in your calculations here? As far as im aware, a date diff will look at actual dates and times, regardless of what your working hours are set to. Itll also factor weekends in.

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.
Oct 31, 2022

Hi @Chris Carpenter 

For automation rules, there is a business days, unit of measure option for diff().  That one is based on weekdays and not any site or project-defined values for working days.

There is no option for "working hours".  I have seen community posts where people added math operations to adjust for "working" time frames.

Kind regards,
Bill

Like Chris Carpenter likes this

Suggest an answer

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

Atlassian Community Events