Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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
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.
How can we do issue.getresolutionDate().time - issue.getCreated().time? Is that correct to plug into new Date().getTime() - issue.getCreated().time?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is a great straight forward solution. Is there another solution that could calculate in realtime though?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then you need to convert the age to days, use the number searcher, and the number template...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
getDurationString returns something like "3 weeks", so if that's what you want you need to change the indexer, probably change it to None.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Lacey - what are you trying to do here? Get some duration period in days?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.