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

Convert Milliseconds to Day Hours Min Format using Scripted Field

Hi All, I have 2 custom field date-time picker, and I want to get the difference of them using scripted field, but my field returns milliseconds. How can I convert it to days hours using:

Search Template : Duration Picker or Date Time Range Picker

Template : Custom ,

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


script -->

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

1 answer

1 vote

Hello @Alvin

In your code the statement

dateValue.getTime() - dateValue2.getTime()

returns long value and you are trying to cast it to "Date" thus you see this error.

Instead you should return

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

Hi @Tarun Sapra , thank you for a quick response . Can you check this out, I configured my code based on your suggestion but it returns like this:

Description :

Screenshot from 2018-10-02 09_49_03.png



 Screenshot from 2018-10-02 09_48_44.png

I need to return it something like XX Days XX Hours XX Mins, can you help me out? Thanks!

Tarun Sapra Community Leader Oct 02, 2018

Hello, @Alvin in order to return the value in days, hours etc, it's possible to do that. Just use JiraDurationUtils.

Hi @Tarun Sapra , I already managed to do that, but it is visible on Description Tab. not on the Dates Tab, how can I fix that?

Tarun Sapra Community Leader Oct 02, 2018

Hello @Alvin

In the custom template, use the following snippet


And from your script return (i.e. returned value should be long) which is passed to jira duration utils.

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

223 views 0 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you