Calculate days between dates

Hi,

I want to be able to calculate the number of days between two dates and store the value in a field that can be used within a filter. This can be calculated and stored based on workflow as it would be calculated on the closure of the issue.

Javascript or free plugin in suggestions are welcome.

Thanks in advance

Dan

3 answers

1 accepted

1 vote
Accepted answer

I used Kepler custom fields and a sil script custom field to acheive what was required.

Note: this does not return the days but the minutes between the dates, this needs to be divided by (60*working hours in a day as set in system*number of working days in the system) to provide the days.

0 votes

Look at scripted fields from Script runner plugin.

I use a script field in Script Runner

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import  java.util.Date.*

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('customfield_15968');

def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_15967');

if(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2)) {

   def dateValue = issue.getCustomFieldValue(dateFieldObject) as Date
   def dateValue2 = issue.getCustomFieldValue(dateFieldObject2) as Date
   def calculation = (dateValue - dateValue2)
    
   return (calculation as String)
}

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,418 views 15 19
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