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

This widget could not be displayed.

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.

This widget could not be displayed.

Look at scripted fields from Script runner plugin.

This widget could not be displayed.

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
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

179 views 1 3
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