It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Age of the Issue

Venkat Apr 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

2 votes
Answer accepted
JamieA Apr 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.

Venkat Apr 14, 2013

Hi Jamie,

Thank You.

Kathryn Allison Dec 02, 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 Dec 02, 2014

NVM...went a different route

saurabh Feb 22, 2018 • edited

@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 Jan 14, 2019

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

1 vote
David Webb Apr 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 Apr 25, 2013

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

Bhupesh Nagda Dec 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 Dec 26, 2014

@Jamie Echlin [Adaptavist]

JamieA Dec 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 Nov 04, 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 Nov 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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Join our webinar: “Asset Management: The Role of Context in ITSM” with Atlassian & Riada

  Hi Atlassian Community! This is Teresa from the Jira Service Desk team. On June 19th, I’ll be hosting a webinar “Asset Management: The Role of Context in ITSM” with Atlassian Partne...

166 views 2 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you