script to calculate time since created date

I have a custom script field "time since created". I want to do something like this but need help with the proper syntax. Thanks in advance!

if status = Open

return (today - date_created)

if status = Acknowledged

return (acknowledged - date_created)

3 answers

I found an older post

which partially solves my problem. I used the answer to calculate how long an issue has been in the Acknowledged state. I would also like to use it to calculate how long an issue has been in the Open state. The problem is, I think it is calculating time between created and Open which is 0m. Is there any way to modify this?


On JIRA OnDemand it might be possible to achive something similar using Lambda plugin, e.g. expression: == 'Open' ? (issue.fields.created | sinceNow) : ''

Please let me know if you'd like to make it work.

Calculated fields are not really suitable for values which use "now" as an input, they will only get indexed when the issue is changed, so you can't usefully query on them.

I think this is discussed here... there are also examples similar to what you're trying to do.

thanks Jamie, I actually already found that link and followed the example for "Total time this issue has been In Progress". I got it working to calculate how long the issue has been in "Acknowledged" but I can't get it to work for "Open". My workflow is Open - Acknowledged - Resolved - Closed. Any thoughts?

Thank you!

Since I have been unsuccessful at calculating Time since Created. I am using a custom field called "Reported" which defaults to the current date/time or can be overwritten by the user.

Can you help me with the syntax for calculating the difference between Reported and now?

The script I am using, below, works for calculating Time since Acknowledged. Acknowledged is a workflow state, Reported is not. How can I modify this to not look for "status"?

import com.atlassian.core.util.DateUtils

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.issue.history.ChangeItemBean

def componentManager = ComponentManager.getInstance()

def changeHistoryManager = componentManager.getChangeHistoryManager()

def OpenName = "Acknowledged"

def rt = [0]

changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->

def timeDiff = System.currentTimeMillis() - item.created.getTime()

if (item.fromString == OpenName) {

rt << -timeDiff


if (item.toString == OpenName){

rt << timeDiff



// NOTE: doesn't show anything if less than 60 seconds

DateUtils.getDurationString(Math.round(rt.sum() / 1000))

We love this but would like to know is it possible to do this without status or is there a way to include all of our status's except close.

Kevin - could you ask a new question with a bit more detail... I have lost the context here. thanks.

We love the format of this showing weeks, days, hours, etc but we need it to be able to show total time from since open no matter the status as well as exclude weekends.  We are currently using the following


import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.sql.Timestamp
import java.text.SimpleDateFormat

// Grab current date, and wipe out time component
Calendar cal = Calendar.getInstance()

// Convert to GregorianCalendar
GregorianCalendar gcal = (GregorianCalendar) cal

// Get the Values of the Start date, End Date and Half Day fields and their values
def StartDate = issue.getCreated()
def EndDate = new Timestamp(gcal.getTimeInMillis())

//initialise some variables
float NumberOfDays = 0;
float TotalNumberOfDays = 0;

// Calculate the number of days that a user has requested
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();

while (cal1.before(cal2)) {
// If the days include weekends skip those days and do not count them
if ((Calendar.SATURDAY != cal1.get(Calendar.DAY_OF_WEEK))
&&(Calendar.SUNDAY != cal1.get(Calendar.DAY_OF_WEEK))) {
}else {

// Add on 1 day to include the start date which the calculation discards
TotalNumberOfDays = NumberOfDays + 0

return TotalNumberOfDays.toString()

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,770 views 18 21
Read article

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