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

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

Script to calculate time between Created and first comment in an issue.


I am trying to implement a scripted field which will calculate time between issue created and first comment added to it. can someone please help with the script. I am not sure how to capture comment time in script. 

1 answer

I'm not sure about ScriptRunner, but using JMCF, you would write something like this:

if (!issue.get("comment"))
  return null;
return new Date().time - issue.get("comment").first().created.time

which would return a number of milliseconds.

Thank you David!

I have used the following code :


import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()
def comments = commentManager.getComments(issue)

((comments[0].created.getTime() - issue.getCreated().getTime()) /1000)as Long)


It is giving me the desired result. please suggest if your one is more optimized? i can use that.

No. Mine would only work with JMCF or JMWE, not ScriptRunner. 

That script looks fine for scriptrunner. The only thing is you will get an error if there are no comments.

You could use the following if you wanted to display the time elapsed so far:

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
def comments = ComponentAccessor.commentManager.getComments(issue)
def endTime = new Date().time
endTime = comments.first().created.time
((endTime - issue.created.time )/1000) as Long

Or make a small adjustment to return null when there are no comments. 

Like hbhardwaj3 likes this

Suggest an answer

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

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

265 views 2 5
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