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

ScriptRunner - Copy Date field (Date only, not time) to Label field


I need the issue statistics or 2-dimensional statistic dashboard gadget to group by date.  For our current need, the calendar gadget will not work.

Due to this, I'm trying a workaround where I copy the date from a date field and create a label.  When I copy from the field, the problem is that it creates 3 labels; the date, the time (12-hour format), and AM/PM.  I only want the date to be copied.


Is there a way on a post-function script that ScriptRunner could copy just the date to the custom label field?

1 answer

1 vote
Craig Nodwell Community Leader May 17, 2022

Hi @Matt Noe you can use the java date routines in scriptrunner.

This example was used to trigger a script in a job that would publish a report to confluence from jira but it's  a good example of using the date functions:

import java.text.SimpleDateFormat
import java.sql.Timestamp
import java.text.DateFormat
import java.util.Date

// retrieve details of the current date so that we can run at midnight first day of month against prior month
def cal = Calendar.instance;
def currentYear = cal.get(Calendar.YEAR);
def currentMonth = cal.get(Calendar.MONTH);

// set the month instance to the start of the previous month
if ( currentMonth == 0 ) {
cal.set(currentYear-1, 11, 1);
} else {
cal.set(currentYear, (currentMonth-1), 1); // comment this line to run the report mid-month for current month
//cal.set(currentYear, (currentMonth), 1); // uncomment this line run the report mid-month re:remove the -1 from (currentMonth-1)

// extract the date, and format it to a string
Date previousMonthStart = cal.time;
String previousMonthStartFormatted = previousMonthStart.format('yyyy-MM-dd');
String previousMonthStartFormattedwithName = previousMonthStart.format('MMM-yyyy');
def today = new Date().format('MMM-dd-yyyy'); //for mid-month report run


Here's anther example in the Scriptrunner library


Hope this helps.

Suggest an answer

Log in or Sign up to answer
Site Admin
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,829 views 37 48
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