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

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

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.

Hi Jamie,

Thank You.

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

NVM...went a different route

@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 ?

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

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?

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

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!!

@Jamie Echlin [Adaptavist]

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

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

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

Localize Smarter with the Transifex Integration for Bitbucket

Over 52% of internet users say obtaining information in their own language is more important than price and 75% of the world’s population doesn’t speak English. It’s no wonder then that successful gl...

224 views 0 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