Age of the Issue

V April 11, 2013

Hi All-

We are trying to calculate the age of each issue created in Jira. For this we have created a custom field of type Script Field. I am new to groovy.

Can some one help me in getting the age of the issue (current time - created date).

Any help is much appreciated.

Thanks in Advance,

Venkat

2 answers

1 accepted

3 votes
Answer accepted
JamieA
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.
April 12, 2013

This is pretty straightforward:

import com.atlassian.core.util.DateUtils

DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().time) / 1000) as Long)

However, it may not do what you expect, as the value for a field is calculated at the time an issue is displayed, or updated. It's not updated in realtime.

NB - the code is suitable for the text template.

V April 14, 2013

Hi Jamie,

Thank You.

Kathryn Allison December 2, 2014

How can we do issue.getresolutionDate().time - issue.getCreated().time? Is that correct to plug into new Date().getTime() - issue.getCreated().time?

Kathryn Allison December 2, 2014

NVM...went a different route

saurabh February 22, 2018

@JamieA : how to get  defect age on basis of following condition

1. if defect is closed:  created date - closed date ? 

if defect is not close

current date - created date 

how to put this condition ?

Paul Henry January 14, 2019

This is a great straight forward solution. Is there another solution that could calculate in realtime though?

1 vote
David Webb
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!
April 24, 2013

This works great a displaying the age, but when you add the "Age" column to a list of issues, it sorts alphabetically rather than by actual "Age". Any suggestion on how to account for the proper sorting?

JamieA
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.
April 25, 2013

Then you need to convert the age to days, use the number searcher, and the number template...

Bhupesh Nagda December 26, 2014

Hello @Jamie Echlin @David Webb Can you please help with the formula to get the number of days? I have changed the template to Number field and the searcher template to Number Searcher but it gives me incorrect output in terms of days and error DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().time)/(1000*60*60*24)) as Long) Error==> The indexer for this field expects a java.lang.Double but the script returned a java.lang.String - this will cause problems. Any help will be appreciated Thanks!!

Bhupesh Nagda December 26, 2014

@Jamie Echlin [Adaptavist]

JamieA
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.
December 29, 2014

getDurationString returns something like "3 weeks", so if that's what you want you need to change the indexer, probably change it to None.

Lacey McDonnell November 4, 2016

Changing searcher to None and selecting Custom Template with a $value field works BUT I can't get it to parse down to days.

 

import com.atlassian.core.util.DateUtils

DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().time) / (1000)) as Long)

This works, shows d,h,m

 

import com.atlassian.core.util.DateUtils

DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().time) / (1000*60*60*24)) as Long)

wipes all values entirely

JamieA
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.
November 10, 2016

@Lacey - what are you trying to do here? Get some duration period in days?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events