Days lasted for an issue

Hello, I'm looking for a way to calculate the days an issue lasted in a custom field.

I want to populate a field when an issue closes by doing a simple calculation in a workflow's post function that closes the issue: current date - creation day, any suggestions on how to do that?

2 answers

1 accepted

Thank you for your time, I was looking for a simple answer and I finally found it:

A Calculated Number Field (from JWT) with this Math/Numeric Expression:

({Pause Date} != null? round(({Current date and time} - {Pause Date}) / {DAY}): 0)

Pause Date is the date field that describes when the project was put on hold. The field always calculates what I needed automatically.

Thanks!

0 vote
Alexey Matveev Community Champion Jan 03, 2018

Hello,

You would need an addon for it like Adaptivist ScriptRunner or Power Scripts

I have ScriptRunner, what do I do next?

Alexey Matveev Community Champion Jan 03, 2018

You need to create a post function with a script like this

import com.atlassian.jira.component.ComponentAccessor
import java.util.Date
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue


def csDays = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("text_single_line_field")


Date currentDate = new Date();
Date createdDate = issue.getCreated();
def days = (Integer)( (currentDate.getTime() - createdDate.getTime()) / (1000 * 60 * 60 * 24));
csDays.updateValue(null, issue, new ModifiedValue("", (Object) days.toString()), new DefaultIssueChangeHolder())
Alexey Matveev Community Champion Jan 03, 2018

I also began to learn Power Scripts. In case it can be useful. If you have Power Scripts plugin, you can add a post function with a code like this

#{text_single_line_field} = currentDate() - created;

It would do about the same.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

172 views 1 17
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you