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

Set field value : Is there way to get only the time value from date time picker custom field?

Deleted user Nov 18, 2017



I am using set field value (from groovy expression) post function. 

My requirement is to update a select list field (with options shift 1 m, shift 2, shift 3 etc) based on the "hour" value which should be extracted from custom field date time picker type. 

I use the groovy expression : 

issue.getAsString("Begin Date")

which is giving complete timestamp including date as shown in screenshot below: 

timevalue.pngCan i extract only the time value? 

I appended getTimeString() to the above code but it doesnt seem to work.


Any help?




1 answer

1 accepted

0 votes
Answer accepted


you can use all the methods of the Date class on the result of issue.get("Begin Date"):

For example, to get the hours:

issue.get("Begin Date").getHours()

 Note that Java doesn't have a class to represent just a time value (without a date), so you'll have to manipulate the hours, minutes and seconds as numbers.

Deleted user Nov 18, 2017

Thanks @David Fischer _Appfire_ !

It worked.




@David Fischer _Appfire_ 

Using set field value postfunction

i have tried to copy, ( time-to-resolve) scripted field value in seconds,

to a text field( time-to-resolve(())

which gives output in seconds, 

how do i get the value in (prettyduration format) ? ex( 2w 3d 1m)


Hi Shiva,

you can use this:


@David Fischer _Appfire_ 


Thank you,

That work like a charm!!


can i get in jira format ( where it takes jira date format)

where 5 days a week and 8 hours a day ( like prettyduration)

Yes, use this instead:


Thanks David,

i have added this to post function, But i get the text copied to field as below,



Text is directly copied to the field "time-to-receive(())" text field

     Did i miss any fixes ?



Sorry, I provided the Groovy code. In a Groovy template, just wrap it with ${ and } just like in the previous example:



Like shiva likes this

it Works!!


Thanks for the response.


last step. ( the scipted field shows the result as below)


but the copied text shows,


the script i use is as below, should i divide by 3600 , to get the data as ( 8hours perday,5days per week)




import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.Issue;
import com.atlassian.core.util.DateUtils

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def inprogressname = "Resolve"

List<Long> rt = [0L]

def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each { ChangeItemBean item ->

//def timeDiff = item.created.getTime() - issue.getCreated().getTime()

def timeDiff = System.currentTimeMillis() - issue.getCreated().getTime()

if (item.fromString == inprogressname) {
rt << -timeDiff
if (item.toString == inprogressname){
rt << timeDiff


//return (Math.round(((rt.sum() as Long) / 3600) as Long))

def total = rt.sum() as Long
return (total / 1000) as long ?: 0L

No. You are calculating the field value as a time difference between two date/time values. This is, by definition, an absolute duration in calendar time, meaning it includes nights and weekends. Therefore, you can't convert it/display it in working time, because it would require calculating the time, between the two date/times, spent during working hours only, which is far from trivial.

Got it , thanks .!! David
Thanks for the help.

Can you direct me where I can Browse >> (calculating time in all statuses of workflow)sum of all the statuses.

or any script you are aware of which gives time between statuses with nights & weekends  excluded

I'm not sure I understood the first question. As for the second, it's not as easy as it looks, as you need to take time zones into account, and potentially holidays, vacations, etc.

Maybe someone can share their solution? I don't have a good one for that.

the script i have is for adding time in status for single status,


How do i add time in two statuses, when i add 1st status open it shows blank,


if i add other statuses , other than the first it gives an output.

Hi @David Fischer _Appfire_ ,

I tried using same as above syntax (one with the post-func) but it doesn't work on my config set-up...

scripted customfield to hours is:
TOTAL TIME TO: Ticket Age (hrs) = 

while customfield destination to copy in prettyformat is:
PretDur Ticket Age

Applied your reco syntax: 

${com.atlassian.core.util.DateUtils.getDurationString(issue.get("TOTAL TIME TO: Ticket Age (hrs) ="))}

result: it did not display at all the 'PretDur Ticket Age' field

i tried adding a set of { } in curr syntax as experiment;
it displayed the 'PretDur Ticket Age field but value is single closed bracket }

Screen Shot 2021-12-06 at 2.32.17 AM.png

can you pls. help to isolate what I'm missing? thanks.

Hi @Luz Silverio ,

The question and solution we're for Jira Server/DC. JMWE for Jira Cloud uses a different syntax. You should create a separate Community question, or check out the appropriate product documentation for the cloud. 

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events