Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
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

Scriptrunner - Find the time difference between 2 date / time fields

Edited

I have two date/time fields ("Actual Start" & "Actual End").  Want I want to do is have a scripted field which is the time difference between these 2 dates / time.

So far I've only been able to get an integer response which is representing the days but I need this displayed in minutes / hours etc.

Any help would be appreciated as I’m stuck :(

1 answer

1 accepted

3 votes
Answer accepted
Jenna Davis
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.
Sep 13, 2017

Hello, 

It's not written for your exact situation, but this script should return a calculated 'Date' value:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import  java.util.Date.* 

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObjectByName('FieldA');
def dateFieldObject2= customFieldManager.getCustomFieldObjectByName('FieldB');

if
(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2))
{
def dateValue=  issue.getCustomFieldValue(dateFieldObject) as Date    
def dateValue2=  issue.getCustomFieldValue(dateFieldObject2) as Date    
return dateValue - dateValue2
}

Let me know if you had something else in mind, or if you need help getting it to work for your exact situation. :)

Regards,

Jenna

Hi Jenna,

Thanks for your response.

The outcome of your script is similar to what I get already.  The returned value is an integer so it’s basically only representing days.

What I'd like is to include hours and minutes, not just days.

Jenna Davis
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.
Sep 15, 2017

You can get the number of milliseconds by doing:

return dateValue.getTime() - dateValue2.getTime()

And then convert to hours and minutes from there. 

I didn't know the epoch time was in milliseconds, I was getting this value but didn't realise it was milliseconds.

I have converted this using the link below and I know get the required breakdown of the time difference.

https://stackoverflow.com/questions/12125311/how-to-convert-milliseconds-into-hours-and-days

Thanks again

Mine is returning 19 years when the difference is only one day 0_o

What to do if the second value is only an integer value and i want to get the sum as a date?

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events