The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Matt Noe
Contributor
May 17, 2022

Problem:

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Craig Nodwell
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 Champions.
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.

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events