Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to make a custom field to show the ∆ between two dates

Using a JMCF custom field I need to calculate the time past between two date fields with an mm/dd/yyyy hh:mm:ss. I need to do this inside of a groovy script inside the custom field w/o importing anything else in. 

  1. What type of JMCF field should be used?
  2. What should the formula/expression be?


2 answers

0 votes

Hi @Nick H 

This should work


Date date1 = issue.get("date1");

Date date2 = issue.get("date2");

if (date1 == null || date2 ==null)

  return null;

return (date1.getTime() - date2.getTime())/1000L;

 I think the field type is Calculated (scripted) Duration



0 votes

Hi @Nick H ,

The most natural field type to pick is the Calculated Duration field, which will display its value in duration format (like  Jira's estimated time field). 

The formula should return a number of seconds, and you can use the secondsBetween(...) global function:


Thanks David, looks like this is promising... I messed up and one of the dates is the system "created" date and the other is a custom field that is just dd/mm/yyyy... is there a way to "trim" the system created date to just be dd/mm/yyyy using your formula? Or perhaps a ROUNDUP function similar to an excel formula to put in front of the whole expression? That would work too

Do you mean the custom field is a Date Picker, not a Date/Time Picker? In that case, are you just interested in a number of days between the two dates? If so, the easiest is to round up the Created date:

import org.apache.commons.lang3.time.DateUtils
def created = DateUtils.truncate(issue.created, java.util.Calendar.DAY_OF_MONTH)

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events