Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

479 views 5 19
Read article

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