Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Difference between Two Custom DateTime Field using scripted field

Alvin
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.
September 30, 2018

Hi Community, I have a problem regarding with the datetime field . I am using two datetime custom field. I also use this scripted field by scriptrunner, but it returns an error

I used Date Time Range Picker as a Searcher and a Custom Template :

$datePickerFormatter.withStyle($dateTimeStyle.DATE).format($value)

 

code:

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_10806');

def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_10807');

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

 

it says cannot return value of type long 2382000000 on method for java.util.Date. Thanks

2 answers

1 vote
Alexey Matveev
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.
September 30, 2018

Hello,

Difference between dates is not a date. It is a long value, which represents difference in milliseconds.

Alvin
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.
September 30, 2018

Hi @Alexey Matveev , how can I configure it to convert milliseconds on Day Hour Minute Format?

Alexey Matveev
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.
September 30, 2018
Alvin
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.
September 30, 2018

I am using this one, can you help me?

java.util.concurrent.TimeUnit
Alexey Matveev
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.
September 30, 2018
0 votes
Alvin
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.
October 1, 2018

Hi @Alexey Matveev , can you guide me on this one? I'm using this code but it goes under description. not on the date tabs

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

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('customfield_10806');

def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_10807');

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

def time = dateValue2.getTime() - dateValue.getTime()
long days = TimeUnit.MILLISECONDS.toDays(time);
long hours = TimeUnit.MILLISECONDS.toHours(time) % 24;
long minutes = TimeUnit.MILLISECONDS.toMinutes(time) % 60;

return String.format("%d Days %d Hours %d Minutes ", days, hours, minutes);
}

Alexey Matveev
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.
October 1, 2018

It can not go into the date tab, because it is not a date.

Suggest an answer

Log in or Sign up to answer