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

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


1 badge earned


Participate in fun challenges

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


Gift kudos to your peers

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


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!


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
Community Members
Community Events
Community Groups

Age of issue in Days using Scriptrunner Scripted Field

I've been going through all of the questions and resolutions for creating a field using Scriptrunner to calculate the number of days an issue has been opened.

I'm a novice at scripting so some of the resolutions have not made sense to me.

Here's what I've tried:

First attempt:

import com.atlassian.core.util.DateUtils
DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().time) / 1000) as Long)

Which returns with the format of w  d  h  m

example from one of my issues 31w 2d 12h 33m

Second attempt:

import com.atlassian.core.util.DateUtils
DateUtils.getDurationString(((new Date().getTime() - issue.getCreated().time) / 86400000) as Long)

Which returns as Months

I just need to get days only for my customer - again I'm new at scripting and have been researching this, not finding any recommendations that lead to just days. If there is a rounding that needs to be done to this script or a completely different script - please give me the steps.

Thank you fellow Atlassian Folks!

2 answers

2 accepted

0 votes
Answer accepted

I get my day durations like this when I want whole days.

def durationMillis = new Date().time - issue.created.time
def days= Math.round(durationMillis / 1000 / 60 / 60/ 24)

You could also use Math.floor() if you want a day to be counted only after a full 24 hours has passed. Math.round does a simple arithmetic rounding to the nearest integer.

Thank you! I'll check that out too - I really appreciate this :)

@Peter-Dave Sheehan how does this go into the script? Again, I'm very novice at this and I'm not sure how to insert this

Scripts can be super simple or super complicated. If you don't care that this number will grow forever you can put this is the script exactly as is.

Here is an example:

2020-12-08 14_41_48-Script Fields.png 

But you may want to consider stopping the clock when an issue is closed.

In which case you'll have to introduce some more complex logic.


Something like:

def enDate = issue?.resolutionDate ?: new Date()
def durationMillis = endDate.time-issue.created.time
def days= Math.round(durationMillis / 1000 / 60 / 60/ 24)

Something to note about a field like this ... the index (if you select a searcher in the custom field configuration) will only be updated when an issue is otherwise updated.

So don't expect to be able to use this field in filters and have current results.

Like Beverly Braham-Durica likes this

I'm still getting an error when I use the first method - any suggestions would be great


This is an inconsequential warning. You can safely ignore it. 

If it really bothers you, you can force the data type of your calculation with something like this:

def days= Math.round((durationMillis / 1000 / 60 / 60/ 24) as Double)
Like Beverly Braham-Durica likes this

Thanks for all of your help @Peter-Dave Sheehan  - it works great.

0 votes
Answer accepted

getDurationString translates seconds into a formatted string that breaks down the duration into the largest common divisors.

You should be using one of the other functions, I think.   See for the various options

Thank you - I'll read through these and see which one would be the best.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events