How do I get the year in YYYY format on an issue duedate ?

Hi all,

In one of my projects, I need to get the year data of duedate for all issues.

I want to fill it into a calculated  customfield. I find a code but did not work. The code is below;

<!-- @@Formula:


if (duedate==null) return null;

return String.format("%tY-%tm", duedate, duedate);


Can anyonehelp me with this ? Thanks..  Levent

2 answers

1 accepted

0 votes
Answer accepted

You need to create a JMCF Calculated Number Field that returns just the year, as a number so that sorting and querying works best. 

The formula would be:

return issue.get(“duedate”) == null ? null : issue.get(“duedate”).getYear() + 1900;

I Have magaged to get it somehow.

The code I used is below:

<!-- @@Formula:
duedateTimestamp = issue.get("duedate");
long timestamp = duedateTimestamp.getTime();
Calendar cal = Calendar.getInstance();
duedateYear = cal.get(Calendar.YEAR);
return duedateYear;

That formula gives me just the year  section of my duedate and that was I need.

Thanks for your help.


0 votes
Ivan Tovbin Community Champion Mar 24, 2018

Go to Administration -> System -> General Configuration -> Advanced Settings and check the settings for and These settings control the way dates are displayed in date picker type fields. For the correct formats check this documentation.

Hi Ivan,

Thanks for responce.

That is not what I need. I do not want to change the format of any dates. I just get the year value ot of duedate and write it down into a customfield. The current format is like  24/Mar/18  ----> I need the year 2018...


Ah, I see.

You can try the following then:

import java.sql.Timestamp;

Timestamp dueDate = issue.getDueDate();
return dueDate.format("MM/dd/yyyy");

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 14, 2019 in Jira

Updates to give you visibility into what's coming in Jira Server and Data Center

Hello, Community! My name is Gosia and I'm a Product Manager on Jira Server and Data Center here at Atlassian. Since 2002 when we launched our public issue tracker, jira.atlass...

643 views 1 15
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you