Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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
4,559,979
Community Members
 
Community Events
185
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
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 12, 2022

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

 

Regards

0 votes
David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 12, 2022

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:

secondsBetween(issue.get("field1"),issue.get("field2"))

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

David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 15, 2022

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)
secondsBetween(created,issue.get("field2"))

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events