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

How to set a Date-Time Picker field with value of Current Date Time excluding seconds/milliseconds

I want to populate a custom field of type Date-Time picker with Current Date and Time and I want to take the time factor only for hours and minutes i.e. in the format "dd.MM.yy HH:mm" and exclude seconds and milliseconds. The functionality has to implemented a Custom Script Post Function. Kindly suggest the groovy script for same.

1 answer

Hello Swapnil,

Per your description, I believe you are needing to add a post function to automatically update a date & time custom field with the current date and time of your instance timezone. Is it correct?

If you re using JIRA Server, I believe you can achieve this need by using Scriptrunner App and use the following Groovy script as a template in your post function:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest

import java.sql.Timestamp

issue.setCustomFieldValue(
        ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("customFieldname")
        , new Timestamp()
)

//only for create transition
/*
ComponentAccessor.getIssueManager().updateIssue(
        ComponentAccessor.getJiraAuthenticationContext().getUser()
        , issue
        , UpdateIssueRequest.builder().sendMail(false).eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).build()
)
*/

If you are using JIRA Cloud, you can use the Update Custom field post function and add the value %%CURRENT_DATETIME%% to it.

P.S: you can use this same post function in JIRA Server too, however, you must install the JIRA Suite Utilities app to use that Post Function.

Let me know if this information helps.

Hello @Petter Gonçalves

I am sorry, that did not help as I did not want the seconds and milliseconds part of the current time. 

Following script helped me to resolve the issue.

https://community.atlassian.com/t5/Jira-questions/Store-current-date-in-post-function/qaq-p/244632 .

Thank you for taking out your time and responding.

Regards,

Swapnil Srivastav

Thank you for sharing the option you found to achieve your need, Swapnil.

Have a nice weekend! :)

Suggest an answer

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

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

314 views 1 3
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