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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Script need to be modified

Hi Team,

I have implemented a script to calculate Number if weeks from start date to end date, see below:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import java.util.Date.*
import static java.lang.Math.*
import java.sql.Timestamp

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('customfield_18880');

def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_12110');

if(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2)) {
def dateValue= issue.getCustomFieldValue(dateFieldObject) as Date
def dateValue2= issue.getCustomFieldValue(dateFieldObject2) as Date

def diffdate = dateValue - dateValue2
double noofweeks = diffdate/7

double roundNoOfWeeks = Math.round(noofweeks)

int value = (int) roundNoOfWeeks;

return value



Now I need some modification in it, 

So the current calculation is (Today - Start date), then once reach the End date, the calculation will be (End date - Start date).

So need Number of weeks =  Today's date(system date) -Start Date


If one issue reached to end date then Number of weeks = End Date-Start date.


Kindly please help me to modify this, I am not aware how to get the system date in the script.



Neeta Jain

1 answer

3 votes

Hi @neeta jain 

You can can current date/time using this code.

Date dateObj = new Date()
def timestamp = new SimpleDateFormat('dd-MM-yyyy--HH-mm').format(dateObj)

Also please look for scripts on you will find plenty of examples.


Hi Ravi,

After adding above 2 line code, its giving an error that simpledateformat is not available?

Can you please suggest the solution for it.



Neeta Jain

Like Ravi Sagar _Adaptavist_ likes this

Hi @neeta jain 

You need to add this line on top as well.

import java.text.SimpleDateFormat


Thanks Ravi.

But when i return the value for timestamp, it just giving 14(today's date)

I wanted to apply formula for system date - end date.

So how would I get the exact date format, so that i can apply the formula.



Neeta Jain

You can modify the format if you want by modifying the argument


Did you take a look at the example scripts on library? Take a look at this script to understand how to work with dates.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Opsgenie

Investigate deployment-related incidents with Bamboo and Opsgenie together

Back in April of last year one of the major product announcements from Opsgenie was the launch of the Incident investigation view which created a deep connection between Bitbucket and Opsgenie, empow...

93 views 1 4
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