Calculate days between dates

Dan Flint
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 29, 2012

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
Answer accepted
Dan Flint
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 5, 2012

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
Christopher Gronde May 23, 2018

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)
}

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 29, 2012

Look at scripted fields from Script runner plugin.

Suggest an answer

Log in or Sign up to answer