Scriptrunner Change Date Format

Jamie Rogers November 27, 2019

Hi Community

I would like some assistance with scriptrunner - I want to return the Due Date value in a preferred format as currently with Dataplane reports the date format (as displayed) is not ideal.

Currently in Dataplane the Due Date value is displayed as YYYY/MM/DD however several teams want this to be displayed as DD/MM/YYYY instead (like it is in Jira). Dataplane vendor (Arsenale) advised their addon doesn't currently support changing this but suggested a scripted field maybe able to do it.

Essentially I want to create a scripted field that returns the due date value of the issue in my preferred format. I have had a poke around the community forums and appears to be some solutions for customfields, but due date is a system field (and I can't quite work out what to do).

Any help would be greatly appreciated.

Regards, Jamie 

1 answer

1 accepted

1 vote
Answer accepted
Jeff Turner
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.
November 28, 2019

Because this is an internet forum, allow me to first tell you that what you want is wrong. yyyy-mm-dd is God's own format that avoids all ambiguity, sorts naturally and is ISO-approved.

But if you really want to, this Groovy code reformats the due date:

import org.joda.time.format.*
DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy")
fmt.print issue.getDueDate().getTime()

Go to the 'Script Fields' admin section, and create a new Script Field of type 'Custom Script Field', paste that in and preview with an issue that has a due date.

For Groovy scripting, a useful trick is to append '.class' to a known object to find it's type, then google that class to find what methods the class has. I start with 'issue', then find I can do 'issue.getDueDate()', and then google how to format a java.sql.Timestamp.

Jamie Rogers November 28, 2019

Thanks @Jeff Turner this is helpful and will do what the users want for their reporting.

Thanks also for your response - I'll give you a pass since its Friday and I can laugh it off. I guess from user's perspective the 'how it is' way is not helpful since Jira formats date fields in our instance the wrong way round but this is why we have scriptrunner to re-format things all the wrong ways :) 

Suggest an answer

Log in or Sign up to answer