You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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.
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
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"))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.